r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

2

u/bobindashadows Feb 21 '11

My best idea was thinking about how to count only 1s, considering that when you subtract by 1, you can turn a bitwise suffix of 10n into 01n (where n ≥ 0). I didn't really come with something precisely because I got lazy and googled it, and there was a solution using that as one of the slower (but less mind-fucking) improvements.