Easy and Clean Java Solution using bitwise operator and counting bits!!🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nCheck the bits bitwise using right shift operator and count for corresponding bits at e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck the bits bitwise using right shift operator and count for corresponding bits at even and odd position.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake n1 for even count and n2 for odd count.\nKeep a variable idx for index count.\nif index is even, check if element at 0th position is 1, if yes, increment n1\nSimilarly for n2\nFinally, make an array for the counts and return\nSimple!!!\nReach out if you have doubts\n\n# Complexity\n- Time complexity: O(log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] evenOddBit(int n) {\n        int n1 = 0;\n        int n2 = 0;\n        if(n == 0) return new int[]{0, 0};\n        int idx = 0;\n        \n        while(n > 0) {\n            if(idx % 2 == 0) {\n                if((n & 1) == 1) n1++;\n            }\n            else {\n                if((n & 1) == 1) n2++;\n            }\n            idx++;\n            n = (n >> 1);\n        }\n        \n        return new int[]{n1, n2};\n    }\n}\n```\n\n  PLEASEEEE DO UPVOTE IF YOU LIKE IT!!!\n  IT WOULD MAKE MY DAY! :)\n![image.png](https://assets.leetcode.com/users/images/a765b813-28e9-4be0-ac86-11b9c4eb851c_1679703179.3775415.png)\n
['Bit Manipulation', 'Java']