Maximum XOR for Each Query

You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:

  • Find a non-negative integer k < 2^maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length - 1] XOR k is maximized. k is the answer to the i^th query.
  • Remove the last element from the current array nums.

Return an array answer, where answer[i] is the answer to the i^th query.

Example 1
Inputnums = [0,1,1,3], maximumBit = 2
Output[0,3,2,3]
The queries produce k values 0, 3, 2, and 3 as the array repeatedly removes its last element.
Example 2
Inputnums = [2,3,4,7], maximumBit = 3
Output[5,2,6,5]
The queries produce k values 5, 2, 6, and 5 as the array repeatedly removes its last element.

Constraints

  • nums.length == n
  • 1 <= n <= 10^5
  • 1 <= maximumBit <= 20
  • 0 <= nums[i] < 2^maximumBit
  • nums is sorted in ascending order.

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