1388. Count Pairs with XOR in a Range

HardBit ManipulationXOR TrieCountingBit Manipulation

Given an array and two bounds low and high, count the pairs of indices (i, j) with i < j such that low <= nums[i] XOR nums[j] <= high.

Input: A JSON object {"nums": [<non-negative integers>], "low": <lower bound>, "high": <upper bound>}.

Output: Return the number of pairs whose XOR falls in [low, high].

Examples

Example 1
Input: {"nums":[1,4,2,7],"low":2,"high":6}
Output: 6
Explanation: Three pairs have XOR within [2,6].
Example 2
Input: {"nums":[9,8,4,2,1],"low":5,"high":14}
Output: 8
Explanation: Eight pairs fall in the range.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →