You are given a list of integers and an integer x. You may perform one operation at most once: choose any set of indices and add x to every chosen element.
After the operation, the score is the sum of XOR values of every pair of adjacent elements. Return the maximum possible score.
long maximizeXorScore(List<Integer> nums, int x)
nums is the list of integers.x is the value added to every selected element.For a final list b, the score is:
(b[0] xor b[1]) + (b[1] xor b[2]) + ... + (b[n - 2] xor b[n - 1])
Return the maximum score as a long.
1 ≤ nums.size() ≤ 100,0000 ≤ nums[i] ≤ 1,000,000,0000 ≤ x ≤ 1,000,000,000maximizeXorScore(nums = [4, 2, 7], x = 3)
Output: 17
Choose indices 0, 1, and 2. After adding 3 to these indices, the list becomes [7, 5, 10].
The score is (7 xor 5) + (5 xor 10) = 2 + 15 = 17.
maximizeXorScore(nums = [1, 5, 2, 8], x = 4)
Output: 41
Choose indices 0, 1, and 2. After adding 4 to these indices, the list becomes [5, 9, 6, 8].
The score is (5 xor 9) + (9 xor 6) + (6 xor 8) = 12 + 15 + 14 = 41.
maximizeXorScore(nums = [3, 10, 6], x = 0)
Output: 21
Since x = 0, adding 0 does not change any element. The list remains [3, 10, 6].
The score is (3 xor 10) + (10 xor 6) = 9 + 12 = 21.
maximizeXorScore(nums = [6], x = 10)
Output: 0
There is only one element, so there are no adjacent pairs. Therefore, the score is always 0.