Remove duplicates ,sort and find target
IntuitionWe need to count the number of pairs ((a, b)) where the sum of their set bits is at least k.
A brute-force approach would be too slow, so we use binary
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to count the number of pairs \((a, b)\) where the sum of their set bits is at least `k`.  
A brute-force approach would be too slow, so we use **binary search** for efficiency.

# Approach
<!-- Describe your approach to solving the problem. -->
1. **Remove duplicates** from `nums` since duplicates don’t affect the count.
2. **Count the set bits** (number of `1`s in binary representation) for each unique number.
3. **Sort** the bit counts for efficient searching.
4. **Use binary search**:  
   - For each bit count \( x \), find the smallest index where \( y \) satisfies \( x + y \geq k \).
   - Count all valid pairs using the index found.
5. **Sum up the counts** to get the final answer.

# Complexity
- Time complexity:  O(N log N)
  - Sorting takes \( O(N log N) \)
  - Binary search for each element takes \( O(N log N) \)

- Space complexity:  O(N)
  - Storing unique numbers and their bit counts.

# Code
```javascript
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var countExcellentPairs = function(nums, k) {
    // Step 1: Remove duplicates
    let uniqueNums = [...new Set(nums)];

    // Step 2: Count set bits
    const countBits = (num) => num.toString(2).split('0').join('').length;
    let bitCounts = uniqueNums.map(num => countBits(num));

    // Step 3: Sort bit counts
    bitCounts.sort((a, b) => a - b);

    let count = 0;
    let n = bitCounts.length;

    // Step 4: Iterate through bit counts and use binary search
    for (let i = 0; i < n; i++) {
        let target = k - bitCounts[i];
        let left = 0, right = n - 1;

        // Binary search to find the first index where bitCounts[j] >= target
        while (left <= right) {
            let mid = Math.floor((left + right) / 2);
            if (bitCounts[mid] >= target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }

        // Step 5: Count valid pairs
        count += (n - left);
    }

    return count;
};

// Example usage:
console.log(countExcellentPairs([1,2,3,1], 3)); // Output: 5
console.log(countExcellentPairs([5,1,1], 10)); // Output: 0

['JavaScript']