Maximum XOR After Operations
You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).
Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.
Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.
Example 1
Input
nums = [3,2,4,6]Output
7After applying an operation such as
x = 4 at index 3, nums can become [3, 2, 4, 2], whose bitwise XOR is 7, and it can be shown this is maximum.Example 2
Input
nums = [1,2,3,9,2]Output
11Applying zero operations gives bitwise XOR
1 XOR 2 XOR 3 XOR 9 XOR 2 = 11, which is maximum.Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^8