Partition Array to Minimize XOR
You are given an integer array nums and an integer k.
Your task is to partition nums into k non-empty subarrays. For each subarray, compute the bitwise XOR of all its elements.
Return the minimum possible value of the maximum XOR among these k subarrays.
Example 1
Input
nums = [1,2,3], k = 2Output
1The optimal partition is
[1] and [2, 3], whose XOR values are both 1, so the maximum XOR is minimized to 1.Example 2
Input
nums = [2,3,3,2], k = 3Output
2The optimal partition is
[2], [3, 3], and [2], whose XOR values are 2, 0, and 2, so the maximum XOR is minimized to 2.Constraints
- 1 <= nums.length <= 250
- 1 <= nums[i] <= 10^9
- 1 <= k <= n