Almost
Solution #
Let’s start with the highest bit since it’s the most significant. We need to divide elements into two groups, one with elements which is on this bit and the other with elements which is on this bit. If either group is empty, we can always assign 0 or 1 to this bit to make this bit 0 in the answer and we can just proceed to the next bit, otherwise this bit is always 1. In order to know which value to assign we will solve the same problem recursively for each of the groups for the next bit. Let the answer for the two groups be and and the current bit is the answer would be .