Python Solution | Brute Force | Optimized | O(N)
\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        count=0\n        n=len(nums)\n        \n        # Brute Force\n  
```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        count=0\n        n=len(nums)\n        \n        # Brute Force\n        # s=set()\n        # for i in range(n):\n        #     for j in range(n):\n        #         a=nums[i] | nums[j]\n        #         b=nums[i] & nums[j]\n        #         a_count=bin(a).count(\'1\')\n        #         b_count=bin(b).count(\'1\')\n        #         if a_count+b_count>=k and (nums[i], nums[j]) not in s:\n        #             s.add((nums[i], nums[j]))\n        #             count+=1\n        # return count\n        \n        arr=[]\n        for num in set(nums):\n            arr.append(bin(num).count(\'1\'))\n        arr.sort()\n        l=0\n        r=len(arr)-1\n        ans=0\n        while l<=r:\n            if arr[l]+arr[r]>=k:\n                ans+=(r-l)*2 + 1\n                r-=1\n            else:\n                l+=1\n        return ans\n```
['Binary Tree', 'Python', 'Python3']