Problem · Array
Maximum XOR Elimination Score
Learn this problemProblem statement
You are given an integer array nums. Initialize score = 0.
While more than one number remains:
- Choose two remaining numbers
xandy. - Add
x XOR ytoscore. - Remove either
xory; the other chosen number remains unchanged.
Return the maximum score obtainable when exactly one number remains.
Function
maximumXorScore(nums: int[]) → longExamples
Example 1
nums = [1, 2, 3, 4, 5]return = 30An optimal sequence accumulates a total XOR score of 30.
Example 2
nums = [1, 2, 4]return = 11Choose 2 and 4 for a score of 6 and remove 2. Then choose 1 and 4 for 5 more, giving 11.
Constraints
1 <= nums.length <= 10000 <= nums[i] <= 10^9