O(N log N) solution in Python, only 2 lines
Intuition\n Describe your first thoughts on how to solve this problem. \nThis problem is very easy if you observe the property of num1 AND num2 + num1 OR num2 =
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is very easy if you observe the property of `num1 AND num2` + `num1 OR num2` = `num1 + num2`. With this knowledge, this problem is surprisingly easy to find all pairs of numbers that the sum of their set bits >= `k`, very similar to the first Leetcode problem [Two Sum](https://leetcode.com/problems/two-sum/)!\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort the numbers by their set bits and do binary search (or two points if you like) to find the number of pairs with the sum >= `k`.\n\n# Complexity\n- Time complexity: $$O(N \\log N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Additional space is only $O(1)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        nums = sorted([x.bit_count() for x in set(nums)])\n        return sum(len(nums) - bisect_left(nums, k-x) for x in nums)\n```
['Bit Manipulation', 'Sorting', 'Python3']