The first interview - Calculate the set bits of a number.
Anonymous
2 ways I've seen are to use bitset or iterate with the inverted negative. int n = 31; bitset bs = n; int t = bs.count(); int r = 0; while (n) { n &= ~- n; r++; } return r;
Check out your Company Bowl for anonymous work chats.