Trains the technique from
LeetCode 421Maximum XOR of Two Numbers in an ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A lighting desk holds n fixtures. Fixture i is described by the non-negative integer nums[i], whose set bits say which channels that fixture drives.
Pair up two fixtures at positions i and j, where i and j may be the same position. The pair's spread is the number you get by combining the two descriptions with bitwise exclusive-or, so a bit of the spread is set exactly when one fixture of the pair drives that channel and the other does not.
Return the largest spread over all pairs. Pairing a fixture with itself gives a spread of 0, so a desk with a single fixture answers 0.
Example 1
Pairing the fixtures at positions 0 and 2 gives `8 XOR 2 = 10`, the largest spread this desk reaches.
Example 2
Each description has one bit set. Pairing 4096 with 2048 gives a spread of 6144, which is the largest here.
Example 3
Both fixtures drive the same channels, so every pair, including the two distinct positions, spreads to 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_maximum_x_o_r(nums: list[int]) -> int:public int findMaximumXOR(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.