← Discussions on Number of 1 Bits
K kavyasub5
11 Sep 2026, 18:36

Finally got AC after 3 WAs. Sharing what I missed.

XOR cancels equal numbers, and x & (x - 1) clears the lowest set bit. Both give O(1) space solutions here.

3 replies

ayesha_17 1 month ago

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

pbanerjee 1 month ago

You can avoid the extra array and do it in O(1) space.

kavya.g 4 weeks, 1 day ago

Nice. Got asked a variant of this in an interview.

Sign in to reply.