Java Solution with explanation to Beat 100% | if you Like | Upvote Me!**
IntuitionJava Solution with explanation to Beat 100% | if you Like | Upvote Me!ApproachSteps:
k ^= n (XOR operation):
The XOR operation results in a value where
# Intuition
**Java Solution with explanation to Beat 100% | if you Like | Upvote Me!**

# Approach
Steps:
1) k ^= n (XOR operation):

The XOR operation results in a value where each bit is 1 if the corresponding bits of k and n are different, and 0 otherwise.
Integer.bitCount(k) (Count 1 bits):

2)The bitCount method returns the number of 1 bits in the binary representation of k.

3) k &= n (AND operation):

The AND operation updates k to include only the bits that are 1 in both k and n.
Comparison:

If the bit count of the modified k (after k &= n) matches the original cnt (from the XOR operation), return cnt. Otherwise, return -1.

Examples:
Let’s evaluate this with an example:

Input: n = 13 (binary 1101), k = 4 (binary 0100).

k ^= n:
Binary XOR:
 
        1101  ->13
    ^   0100  ->4
    __________
    K= 1001    
Now k = 9 (binary 1001).

count = Integer.bitCount(k):
k = 9 (binary 1001), bitCount = 2.

k &= n:
Binary AND: 

            1001    ->9
        &   1101    ->13
          __________
         K= 1001    number of 1-bit in binary no is 2 so count=2

Now k = 9 (binary 1001).

Comparison:
bitCount(k) = 2, count = 2. They are equal, so the method returns 2.

# Complexity
- Time complexity:
O(1)

- Space complexity:
O(1)

# Code
```java []
class Solution {
    public int minChanges(int n, int k) {
        k ^= n; 
        /* 
            1101  ->13
        ^   0100  ->4
          __________
         K= 1001

        */
        int count = Integer.bitCount(k); 
        /* count number of 1 in binary which is 2 in k*/
        k &= n;

         /* 
            1001    ->9
        &   1101    ->13
          __________
         K= 1001    number of 1-bit 2 so count=2

        */
       
        return count == Integer.bitCount(k) ? count : -1; //count=2
    }
}
```
['Bit Manipulation', 'Java']