1803. Count Pairs With XOR in a Range Hard
1/**
2 * [1803] Count Pairs With XOR in a Range
3 *
4 * Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.
5 *
6 * A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.
7 *
8 *
9 * Example 1:
10 *
11 *
12 * Input: nums = [1,4,2,7], low = 2, high = 6
13 * Output: 6
14 * Explanation: All nice pairs (i, j) are as follows:
15 * - (0, 1): nums[0] XOR nums[1] = 5
16 * - (0, 2): nums[0] XOR nums[2] = 3
17 * - (0, 3): nums[0] XOR nums[3] = 6
18 * - (1, 2): nums[1] XOR nums[2] = 6
19 * - (1, 3): nums[1] XOR nums[3] = 3
20 * - (2, 3): nums[2] XOR nums[3] = 5
21 *
22 *
23 * Example 2:
24 *
25 *
26 * Input: nums = [9,8,4,2,1], low = 5, high = 14
27 * Output: 8
28 * Explanation: All nice pairs (i, j) are as follows:
29 * - (0, 2): nums[0] XOR nums[2] = 13
30 * - (0, 3): nums[0] XOR nums[3] = 11
31 * - (0, 4): nums[0] XOR nums[4] = 8
32 * - (1, 2): nums[1] XOR nums[2] = 12
33 * - (1, 3): nums[1] XOR nums[3] = 10
34 * - (1, 4): nums[1] XOR nums[4] = 9
35 * - (2, 3): nums[2] XOR nums[3] = 6
36 * - (2, 4): nums[2] XOR nums[4] = 5
37 *
38 *
39 * Constraints:
40 *
41 *
42 * 1 <= nums.length <= 2 * 10^4
43 * 1 <= nums[i] <= 2 * 10^4
44 * 1 <= low <= high <= 2 * 10^4
45 *
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/count-pairs-with-xor-in-a-range/
50// discuss: https://leetcode.com/problems/count-pairs-with-xor-in-a-range/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55 pub fn count_pairs(nums: Vec<i32>, low: i32, high: i32) -> i32 {
56 0
57 }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_1803() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.