Hot answers tagged

1

Your code can be more efficient. For example, both nested for-loops can be replaced with single for-loops. In the first loop, the next sum can be calculated by left-shifting the previous sum, adding the new bit, and masking off n-bits. count[sum] is how many times an n-bit pattern == sum has been seen. So the second loop merely counts how many '1's are ...


Only top voted, non community-wiki answers of a minimum length are eligible