Skip to content

Practice Maximum XOR for Each Query

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1829
LeetCode Problem

Maximum XOR for Each Query

Problem Statement

For the current nums, choose a nonnegative k below 2^maximumBit that maximizes the bitwise XOR of k with all remaining entries. Record k, then remove the final entry of nums. Repeat until empty and return the recorded values in query order.

Source: Maximum XOR for Each Query on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [0,1,1,3], maximumBit = 2
Output
[0,3,2,3]

# Example 2

Input
nums = [2,3,4,7], maximumBit = 3
Output
[5,2,6,5]

# Example 3

Input
nums = [0,1,2,2,5,7], maximumBit = 3
Output
[4,3,6,4,6,7]

Constraints

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

Related LeetCode Problems

Practice more problems similar to Maximum XOR for Each Query.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.