Skip to content

Practice Count Pairs With XOR in a Range

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1803
LeetCode Problem

Count Pairs With XOR in a Range

Problem Statement

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.

Source: Count Pairs With XOR in a Range on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,4,2,7], low = 2, high = 6
Output
6

# Example 2

Input
nums = [9,8,4,2,1], low = 5, high = 14
Output
8

Constraints

1 <= nums.length <= 2 * 10^4
1 <= nums[i] <= 2 * 10^4
1 <= low <= high <= 2 * 10^4

Related LeetCode Problems

Practice more problems similar to Count Pairs With XOR in a Range.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.