1398. Count Subarrays with XOR Less Than K

HardBit ManipulationXOR TriePrefix XORCounting

Given an array of non-negative integers and a value k, count the non-empty contiguous subarrays whose XOR is strictly less than k.

Input: A JSON object {"arr": [<non-negative integers>], "k": <threshold>}.

Output: Return the number of subarrays with XOR < k.

Examples

Example 1
Input: {"arr":[1,2,3],"k":3}
Output: 4
Explanation: Four subarrays have XOR strictly below 3.
Example 2
Input: {"arr":[0,0],"k":1}
Output: 3
Explanation: Every subarray XORs to 0 < 1 -> 3.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →