C++ || Sort and Map
\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        map<int,int> mp;\n        for(auto i : nums) mp[i]+=1;\n        int ans=0;\
```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        map<int,int> mp;\n        for(auto i : nums) mp[i]+=1;\n        int ans=0;\n        vector<int> arr = nums;\n        sort(arr.begin(),arr.end());\n        for(int i=0;i<nums.size();i++){\n            auto x = upper_bound(arr.begin(),arr.end(),nums[i]) - arr.begin();\n            while(x<arr.size() && mp[arr[x]]==0) x+=1;\n            if(x<nums.size() && mp[arr[x]] > 0 ){\n                ans += 1;\n                mp[arr[x]] -= 1;\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'Sorting', 'C++']