Two possible solution, easy to understand C++ code!
Intuition\n Describe your first thoughts on how to solve this problem. \nIn two pointer approach we keep track of exactly how many numbers have a number bigger(
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn two pointer approach we keep track of exactly how many numbers have a number bigger(strictly) than it in the same array.\nUSing Multiset also same concept.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSimple two pointer approach and multiset Approach\n\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n//using two pointer approach--->O(nlogn)\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        int n= nums.size();\n        sort(nums.begin(),nums.end());\n        int cnt=0;\n        int i=0,j=1;\n        while(j<n)\n        {\n            if(nums[i]<nums[j])\n            {\n                cnt++;\n                i++;\n                j++;\n            }\n            else\n            {\n                j++;\n            }\n        }\n        return cnt;\n    }\n};\n\n\n// using multiset approach--->O(nlogn)\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        multiset<int> s;\n        sort(nums.begin(),nums.end());\n        for(int i=0;i<nums.size();i++)\n            s.insert(nums[i]);\n        int cnt=0,i=0;\n        while(s.size()>0 && i<nums.size())\n        {\n            auto i1=s.find(nums[i]);\n            if(i1!=s.end())\n             s.erase(i1);\n            auto i2=s.upper_bound(nums[i]);\n            if(i2!=s.end())\n            {\n                cnt++;\n                s.erase(i2);\n                i++;\n            }\n            else\n                 break;\n        }\n        return cnt;\n    }\n};\n```
['Two Pointers', 'C++']