← Discussions on Happy Number
O omkarheg8
15 Sep 2026, 10:30

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

poojamenon 1 month ago

Watch out for integer overflow in Java on the large test.

Sign in to reply.