Easy C++ | Set Bits Logic
First we find the distinct elements from the given vector as duplicates are unnecessary.\nThen we find the setBits of each and every number and store them in a 
First we find the distinct elements from the given vector as duplicates are unnecessary.\nThen we find the setBits of each and every number and store them in a vector.\n    \n**Let two numbers be x and y.**\n**setBits(BITWISE AND of x,y) + setBits(BITWISE OR of x,y) = setBits(x) + setBits(y)**\n\n***Explanation:***\nLet setBits in x = a, setBits in y = b\nBitwise AND represents setBits common in x and y. Let setBits in (x&y) = c\nBitwise OR represents setBits which are either in x or y. So setBits in (x|y) = (setBits in x) + (setBits in y) - common setBits = a+b-c\nTherefore, setBits(BITWISE AND of x,y) + setBits(BITWISE OR of x,y) = c + (a+b-c) = (a+b) = setBits(x) + setBits(y).\n    \nTo evaluate answer, we need to find the excellent pairs. i.e pairs whose (setBits of AND of 2 numbers) + (setBits of OR of 2 numbers) greater than k. \nWe sort the vector in which we stored the setBits.\nWe find the lower_bound for k-v[i], now all the numbers to the right of the lower_bound will form an excellent pair.\n\n**Time complexity: O(N logN)**\n**Space Complexity: O(N)**\n```\nclass Solution {\npublic:\n    typedef long long ll;\n    int setbits(int n){\n        int cnt = 0;\n        while(n){\n            cnt += (n%2);\n            n /= 2;\n        }\n        return cnt;\n    }\n    \n    long long countExcellentPairs(vector<int>& nums, int k) {\n        unordered_set<int> s(nums.begin(),nums.end());\n        vector<int> v;\n        for(auto& i: s){\n            int x = setbits(i);\n            v.push_back(x);\n        }\n        sort(v.begin(),v.end());\n        \n        ll ans = 0;\n        for(int i=0;i<v.size();i++){\n            auto it = lower_bound(v.begin(),v.end(),k-v[i]);\n            ans += (v.end()-it);\n        }\n        return ans;\n        \n    }\n};\n```\n**Upvote if it helps!**
['Binary Search', 'C']