For each array at most ‘2^N’ (size of array) elements can be swapped and changed so that it’s XOR with its index, gives value of ((2^N)-1) (max. possible value after XOR). Any further swaps doesn’t matter. Making 1 swap changes value of 2 elements, thus, making ‘K’ swaps changes value of ‘2K’ elements (only swapping unswapped elements - optimal solution).
A test case to consider is when ‘2K’>‘2^N’, because once ‘2^N’ i.e. all elements have been swapped, swapping further doesn’t matter, the answer would be same.
Thus answer is min(2K,2^N )×((2^N) −1).
And use long long instead of int for calculating power and answer.
@patelyash30 Explained very well but just adding some more details so that you won’t get again wrong answer.
you have to make 2 variables one for storing minimum of two values i.e, min(2K,2^N ).
And the second variable will store maximum possible value in the array you can get i.e, ((2^N) - 1).
then multiply and print both of the variables…
Note : make variables as long long