You are given a non-negative integer array nums and an integer k.
You must select a subarray of nums such that the difference between its maximum and minimum elements is at most k. The value of this subarray is the bitwise XOR of all elements in the subarray.
Return an integer denoting the maximum possible value of the selected subarray.
Example 1:
Input: nums = [5,4,5,6], k = 2
Output: 7
Explanation:
[5, 4, 5, 6].6 - 4 = 2 <= k.4 XOR 5 XOR 6 = 7.Example 2:
Input: nums = [5,4,5,6], k = 1
Output: 6
Explanation:
[5, 4, 5, 6].6 - 6 = 0 <= k.Constraints:
1 <= nums.length <= 4 * 1040 <= nums[i] < 2150 <= k < 215ki, insert their prefix xors pref[i] into a trie (use pref[0] = 0, pref[i + 1] = pref[i] ^ nums[i]); keep counts per node to support deletions as L movesr, query the trie with pref[r + 1] to get the maximum pref[r + 1] ^ pref[l] for l in [L, r][5,4,5,6] 2
[5,4,5,6] 1