C++ | 3 different methods
1st solutionCreate bitset for both input numbers.
Individually check the value of each bit on both input numbers.
Whenever you find a togglable bit, deduce to t
# 1st solution
Create bitset for both input numbers.
Individually check the value of each bit on both input numbers.
Whenever you find a togglable bit, deduce to the input number its corresponding bit value by using the adequate power of 2.
After iterating all the bits, check if both input numbers match.

Time complexity: O(2 * 20 + 1 * (20 + log(20))) = O(61) = O(1)
Space complexity: O(2 * 20) = O(40) = O(1)
```cpp [] 
#include <bitset>
#include <cstdint>
#include <cmath>

class Solution {
public:
    int minChanges(int n, int k) {
        const uint8_t maximum_bits_number = 20; // 10^6 < 2^20
        const std::bitset<20> k_bitset = std::bitset<maximum_bits_number>(k);
        std::bitset<20> n_bitset = std::bitset<maximum_bits_number>(n);
        int8_t bits_changed = 0;
        for (
            uint8_t bit = 0;
            bit < maximum_bits_number;
            bit++
        ) {
            if (n_bitset[bit] == 1 && k_bitset[bit] == 0) {
                bits_changed++;
                n -= std::pow(2, bit);
            }
        }
        if (n != k) {
            bits_changed = -1;
        }
        return bits_changed;
    }
};
```

# 2nd solution
Improvement over 1st solution by not using additional space.
However, time complexity worsens since now in each bit iteration, we have to perform bit shift operations.

Time complexity: O(20 * (20 + 20 + log(20))) = O(826) = O(1)
Space complexity: O(1)
```cpp [] 
#include <bitset>
#include <cstdint>
#include <cmath>

class Solution {
public:
    int minChanges(int n, int k) {
        const uint8_t maximum_bits_number = 20; // 10^6 < 2^20
        int8_t bits_changed = 0;
        for (
            uint8_t bit = 0;
            bit < maximum_bits_number;
            bit++
        ) {
            if (
                ((n & (1 << bit)) != 0)
                && ((k & (1 << bit)) == 0)
            ) {
                bits_changed++;
                n -= std::pow(2, bit);
            }
        }
        if (n != k) {
            bits_changed = -1;
        }
        return bits_changed;
    }
};
```

# 3rd solution
Solution which may be challenging to come by yourself.
Perform a bitwise XOR operation on both inputs.
Perform a bitwise AND operation on the result of the previous bitwise XOR operation and *n* input.
Check if the number of set bits in both bitwise operations match.

Time complexity: O(5 * 20) = O(100) = O(1)
- We can technically save a repeated std::popcount() call

Space complexity: O(1)
```cpp [] 
#include <bit>
#include <cstdint>

class Solution {
public:
    int minChanges(int n, int k) {
        const uint32_t xor_result = n ^ k;
        const uint32_t and_result = n & xor_result;
        int8_t bits_changed = std::popcount(xor_result);
        if (std::popcount(xor_result) != std::popcount(and_result)) {
            bits_changed = -1;
        }
        return bits_changed;
    }
};
```
['C++']