Maximize XOR-AND-XOR over Three Subsequences
Problem statement
You are given an array nums of non-negative integers. Partition its elements into three possibly empty subsequences A, B, and C. Every element must belong to exactly one subsequence.
For an empty subsequence, both its bitwise XOR and its bitwise AND are defined as 0. Return the maximum possible value of XOR(A) + AND(B) + XOR(C).
Function
maximumPartitionValue(nums: int[]) → longExamples
Example 1
nums = [1,2,3]return = 6Choose A = [1,2], B = [3], and C = []. The value is (1 XOR 2) + 3 + 0 = 6.
Example 2
nums = [7,7]return = 14Put one 7 in A and the other in B. This gives 7 + 7 + 0 = 14.
Example 3
nums = [5,1,9,3]return = 16One optimal partition is A = [5,1,9], B = [3], and C = []. Its value is 13 + 3 + 0 = 16.
Constraints
0 <= nums.length <= 15.0 <= nums[i] <= 1000000000.