← Happy Number
Discussions
Sign in to join the discussion.
S
saiaga1
OFFICIAL
4 months, 2 weeks ago
Clean C++ solution, beats most submissions.
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 1 reply
O
omkarheg8
1 month ago
Intuition + complexity breakdown for Happy Number.
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 1 reply
T
tkumar
1 month, 1 week ago
Simple approach explained for beginners.
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 3 replies