Count set bits in an integer

1 min read

https://practice.geeksforgeeks.org/problems/set-bits0143/1

class Solution {
public:
  int setBits(int N) {
    int bCount = 0;
    while (N) {
      N &= (N - 1);
      bCount++;
    }

    return bCount;
  }
};
Maximum length of pair chain
Find the two non-repeating elements in an array of repeating elements