Easy Understand | Simple Method | Java | Python ✅
Approach\n Describe your approach to solving the problem. \nThe problem requires us to count the number of set bits (bits with value 1) at even and odd position
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe problem requires us to count the number of set bits (bits with value 1) at even and odd positions in the binary representation of the given integer n.\n\nOne way to solve this problem is to iterate over each bit of the binary representation of n and check whether it is set or not. For each set bit, we can check whether its position is even or odd and increment the corresponding counter.\n\n# Code\n``` java []\nclass Solution {\n    public int[] evenOddBit(int n) {\n        int even = 0, odd = 0;\n        int digit = 0;\n        while (n > 0){\n            if ((n & 1) == 1){\n                if (digit%2 == 0)\n                    even += 1;\n                else\n                    odd += 1;\n            }\n            digit += 1;\n            n >>= 1;\n        }\n        return new int[]{even, odd};\n    }\n}\n```\n``` python3 []\nclass Solution:\n    def evenOddBit(self, n: int) -> List[int]:\n        even, odd = 0, 0\n        digit = 0\n        while n:\n            if n&1:\n                if digit%2:\n                    odd += 1\n                else:\n                    even += 1\n            digit += 1\n            n >>= 1\n        return [even, odd]\n```\n\nPlease UPVOTE if helpful\uD83D\uDC4D
['Bit Manipulation', 'Python', 'Java', 'Python3']