Partition Array for Maximum XOR and AND
You are given an integer array nums.
Partition the array into three possibly empty subsequences A, B, and C such that every element of nums belongs to exactly one subsequence.
Your goal is to maximize the value of XOR(A) + AND(B) + XOR(C), where:
XOR(arr)denotes the bitwise XOR of all elements inarr; ifarris empty, its value is defined as0.AND(arr)denotes the bitwise AND of all elements inarr; ifarris empty, its value is defined as0.
Return the maximum value achievable.
Note: If multiple partitions result in the same maximum sum, you can consider any one of them.
Example 1
Input
nums = [2,3]Output
5One optimal partition is
A = [3], B = [2], and C = [], giving 3 + 2 + 0 = 5.Example 2
Input
nums = [1,3,2]Output
6One optimal partition is
A = [1], B = [2], and C = [3], giving 1 + 2 + 3 = 6.Constraints
- 1 <= nums.length <= 19
- 1 <= nums[i] <= 10^9