Java Solution using Inclusion Exclusion Principle and Map
Inclusion Exclusion Priniciple\nsetBits(A&B)+setBits(A|B) = setBits(A) + setBits(B)\nThis is the basic principle which will be used to solve the problem.\nWe wi
**Inclusion Exclusion Priniciple**\n*setBits(A&B)+setBits(A|B) = setBits(A) + setBits(B)*\nThis is the basic principle which will be used to solve the problem.\nWe will store the quantity of different number of set bits obtained from the given array of numbers. The only remaining catch is that we must avoid increasing the set bits count for duplicate elements in the array.\nThe data will be stored in a map and we will keep adding the transversed elements in a set and we will only increase the count if and only if the element is not present in the set.\nAt last we will traverse through the different key sets of the map and we will check the pairs where the sum of keys is greater than equal to k.\n\n**TC: O(n)**\n```\nclass Solution {\n    public long countExcellentPairs(int[] nums, int k) {\n        Map<Integer, Integer> map = new HashMap<>();\n        Set<Integer> set = new HashSet<>();\n        for(int i = 0;i<nums.length;i++){\n            int bitCounts = Integer.bitCount(nums[i]);\n            if(!set.contains(nums[i])&&map.containsKey(bitCounts)){\n                set.add(nums[i]);\n                map.put(bitCounts, map.get(bitCounts)+1);\n            }\n            else{\n                if(!set.contains(nums[i])){\n                    map.put(bitCounts, 1);\n                    set.add(nums[i]);\n                }\n            }\n        }\n        long ans = 0;\n        for(int i: map.keySet()){\n            for(int j : map.keySet()){\n                if(i+j>=k){\n                    ans+=map.get(i)*map.get(j);\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Ordered Set', 'Java']