Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
In problems involving bitwise operations, we often think on the bits level. In this problem, we can think that to maximize the result of an xor operation, we need to maximize the most significant bit, then the next one, and so on.
If there's some number in the array that is less than m and whose the most significant bit is different than that of x, then xoring with this number maximizes the most significant bit, so I know this bit in the answer is 1.
To check the existence of such numbers and narrow your scope for further bits based on your choice, you can use trie.
You can sort the array and the queries, and maintain the trie such that in each query the trie consists exactly of the valid elements.