All problems
0615MediumArrayHash TableBit ManipulationTrie

Largest Channel Spread

Tracked in this browser only
Write code

Trains the technique from

LeetCode 421Maximum XOR of Two Numbers in an Array

This 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.

Examples

Example 1

Input
nums = [8, 10, 2]
Output
10

Pairing the fixtures at positions 0 and 2 gives `8 XOR 2 = 10`, the largest spread this desk reaches.

Example 2

Input
nums = [1024, 2048, 4096]
Output
6144

Each description has one bit set. Pairing 4096 with 2048 gives a spread of 6144, which is the largest here.

Example 3

Input
nums = [5, 5]
Output
0

Both fixtures drive the same channels, so every pair, including the two distinct positions, spreads to 0.

Constraints

  • 1 <= nums.length <= 2 * 10^5
  • 0 <= nums[i] <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def find_maximum_x_o_r(nums: list[int]) -> int:
Java
public int findMaximumXOR(int[] nums)
September 7
Apply