Count Pairs With XOR in a Range
Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.
A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.
Example 1
Input
nums = [1,4,2,7], low = 2, high = 6Output
6All 6 pairs have XOR values within the range [2, 6].
Example 2
Input
nums = [9,8,4,2,1], low = 5, high = 14Output
8There are 8 pairs whose XOR values are between 5 and 14 inclusive.
Constraints
- 1 <= nums.length <= 2 * 10^4
- 1 <= nums[i] <= 2 * 10^4
- 1 <= low <= high <= 2 * 10^4