We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There's slight difference. The mentioned n &= (n-1) operation actually counts total set-bits. This problem requires maximum consecutive set-bits.
Example :
For binary 1110011, the number of set-bits are 5 (this will be result of the mentioned operation). But, the required answer would be 3, since maximum number of consecutive set-bits are 3.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Consecutive 1's in Binary Numbers
You are viewing a single comment's thread. Return to all comments →
There's slight difference. The mentioned
n &= (n-1)
operation actually counts total set-bits. This problem requires maximum consecutive set-bits.Example :
For binary
1110011
, the number of set-bits are 5 (this will be result of the mentioned operation). But, the required answer would be 3, since maximum number of consecutive set-bits are 3.