Skip to content

Practice Number of Excellent Pairs

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

Hard#2354
LeetCode Problem

Number of Excellent Pairs

Problem Statement

Count ordered value pairs (a,b) where both values occur in nums and popcount(a OR b) + popcount(a AND b) is at least k. Count each value pair once regardless of duplicate occurrences. Pairs (a,a) are allowed with a single occurrence; (a,b) and (b,a) are different when a differs from b. popcount counts the binary one-bits of its argument.

Source: Number of Excellent Pairs on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3,1], k = 3
Output
5

# Example 2

Input
nums = [5,1,1], k = 10
Output
0

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
1 <= k <= 60

Related LeetCode Problems

Practice more problems similar to Number of Excellent Pairs.

Review your practice with PhantomCodeAI

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