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^maximumBitsuch thatnums[0] XOR nums[1] XOR ... XOR nums[nums.length - 1] XOR kis maximized.kis the answer to thei^thquery. - 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
Input
nums = [0,1,1,3], maximumBit = 2Output
[0,3,2,3]The queries produce k values 0, 3, 2, and 3 as the array repeatedly removes its last element.
Example 2
Input
nums = [2,3,4,7], maximumBit = 3Output
[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.