Beginner friendly Approach
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n    public int[] evenOddBit(int n) {\n        \n        int eve
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int[] evenOddBit(int n) {\n        \n        int even = 0;\n        int odd = 0;\n\n        int idx = 0;\n\n        while (n > 0) {\n\n            // Getting bits from the number\n            int rem = n % 2;\n            \n            // If the index is even and rem is 1     \n            if (idx % 2 == 0 && rem == 1) {\n\n                even += 1;\n\n            } else if (idx % 2 != 0 && rem == 1) {\n\n                odd += 1;\n\n            }\n\n            idx += 1;\n            \n            // Modifying the number.\n            n = n / 2;\n        }\n        \n        // Creating a two size array  \n        int ans[] = new int[2];\n\n        ans[0] = even;\n        ans[1] = odd;\n\n        return ans;\n    }\n}\n\n\n```
['Java']