Bit Manipulation 3226. Number of Bit Changes to Make Two Integers Equal ¶ Time: $O(1)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7class Solution { public: int minChanges(unsigned n, unsigned k) { // n needs to be a superset of k. return (n & k) == k ? popcount(n ^ k) : -1; } }; 1 2 3 4 5 6class Solution { public int minChanges(int n, int k) { // n needs to be a superset of k. return (n & k) == k ? Integer.bitCount(n ^ k) : -1; } } 1 2 3 4class Solution: def minChanges(self, n: int, k: int) -> int: # n needs to be a superset of k. return (n ^ k).bit_count() if (n & k) == k else -1