Welcome to the world of XOR operations! In this challenging problem, you need to find pairs of numbers whose XOR result falls within a specific range.
Given an integer array nums and two integers low and high, your task is to count all "nice pairs" in the array.
A nice pair is defined as a pair (i, j) where:
0 <= i < j < nums.length(i comes before j)low <= (nums[i] XOR nums[j]) <= high(XOR result is within range)
Example: If nums = [1, 4, 2, 7], low = 2, and high = 6, then pair (1, 4) has XOR value 1 โ 4 = 5, which is within range [2, 6].
The challenge lies in efficiently computing XOR values for all pairs while staying within time limits for large arrays.
Input & Output
Visualization
Time & Space Complexity
Each number requires O(log(MAX_VAL)) time for Trie operations, done for n numbers
Trie stores up to n numbers, each with log(MAX_VAL) bits
Constraints
- 1 โค nums.length โค 2 ร 104
- 1 โค nums[i] โค 2 ร 104
- 1 โค low โค high โค 2 ร 104
- XOR operations are bitwise exclusive OR