Easy  Sorting + Greedy , ✅✅
\n# Complexity\n- Time complexity:O(N * Long(N))\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# Complexity\n- Time complexity:O(N * Long(N))\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```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& arr) {\n        int n = arr.size(),ans = 0;\n        sort(arr.begin(),arr.end());\n        if(n<=1) return 0;\n\n        int i = 0,j = 0;\n        while(i<n && j<n)\n        {\n           while(j<n && arr[j]==arr[i])\n           j++;\n           if(i<n && j<n && arr[i]<arr[j])\n           {\n               ans++;\n               j++;\n               i++;\n           }\n        }\n        return ans;\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/66bb2d25-340c-4f24-ab45-ec17eec995e5_1688119301.996845.jpeg)\n
['Greedy', 'Sorting', 'C++']