Maximum XOR of Two Numbers in an Array
Given an integer array nums, return the maximum value of nums[i] XOR nums[j] over all pairs of indices i and j.
Open official problem prompt ↗Find the pair of numbers whose bitwise XOR is as large as possible.
Like choosing a dance partner whose outfit contrasts yours as much as possible, starting with the most visible feature (the top bit) and working down.
- Input
- nums = [3, 10, 5, 25, 2, 8]
- Output
- 28
- Why
- 5 XOR 25 = 28, the largest XOR achievable by any pair.
1 <= nums.length <= 2 * 10^50 <= nums[i] <= 2^31 - 1