#3845

Maximum Subarray XOR with Bounded Range

hard · 31.1% accepted · 61 likes · top 9%

array · bit manipulation · trie · queue · sliding window · prefix sum · monotonic queue

Description

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.

Solution