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
Inputnums = [3,2,4,6]
Output7
After 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
Inputnums = [1,2,3,9,2]
Output11
Applying 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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate