C++ Solution || Well Explained || Beats 100% 💯💯
Code\n\nclass Solution {\npublic:\n    vector<int> evenOddBit(int n) {\n        // vec to store counts of even and odd bits\n        vector<int> ans(2, 0);\n   
# Code\n```\nclass Solution {\npublic:\n    vector<int> evenOddBit(int n) {\n        // vec to store counts of even and odd bits\n        vector<int> ans(2, 0);\n        // counter for posn of bit\n        int i = 0;\n        // iterate through bits of n\n        while(n) {\n            // check if posn is even\n            if (i % 2 == 0) {\n                // inc count of even bits if the curr bit is 1\n                ans[0] += n % 2;\n            }\n            else {\n                // inc count of odd bits if curr bit is 1\n                ans[1] += n % 2;\n            }\n            // move to the next bit by div n by 2\n            n /= 2;\n            // inc posn counter\n            i++;\n        }\n        // return counts of even and odd bits\n        return ans;\n    }\n};\n```
['Bit Manipulation', 'Iterator', 'C++']