O(1) || Bit Manipulation
Approach\n1. Identify Bit Differences: Use the XOR operation between n and k to identify differing bits. The XOR result will have 1 in each bit position where n
# Approach\n1. **Identify Bit Differences:** Use the XOR operation between n and k to identify differing bits. The XOR result will have 1 in each bit position where n and k differ.\n\n2. **Count Bit Differences:** Count the number of 1 bits in this XOR result. This count represents the total number of bits that differ between n and k.\n3. **Check Feasibility of Changes:** Perform a bitwise AND between the XOR result and n. Count the number of 1 bits in this result. If this count is equal to the count from the XOR result, it means that all differing bits are set to 1 in n and can be changed to match k. If not, it\'s impossible to make n equal to k using the allowed changes.\n\n4. **Return Result:** Return the count of differing bits if they can all be changed; otherwise, return -1.\n\n\n\n\n# Complexity\n- Time complexity: $$O(1)$$\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```C++ []\nclass Solution {\npublic:\n    int minChanges(int n, int k) {\n        k ^= n;\n        int cnt = __builtin_popcount(k);\n        k &= n;\n        return cnt == __builtin_popcount(k) ? cnt : -1;\n    }\n};\n```\n```Java []\nclass Solution {\n    public int minChanges(int n, int k) {\n        k ^= n;\n        int cnt = Integer.bitCount(k);\n        k &= n;\n        return cnt == Integer.bitCount(k) ? cnt : -1;\n    }\n}\n\n```\n```Python3 []\nclass Solution:\n    def minChanges(self, n: int, k: int) -> int:\n        k ^= n\n        cnt = bin(k).count(\'1\')\n        k &= n\n        return cnt if cnt == bin(k).count(\'1\') else -1\n\n```\n\n# STL Function Implementaion:\n```\nint popcount(int n){\n    int count = 0;\n    while(n > 0){\n        count++;\n        n = n & (n - 1);\n    }\n    return count;\n}\n```\n
['C++', 'Java', 'Python3']