Simple java solution using two pointer
\n\n# Complexity\n- Time complexity: O(n log n) \n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n    public int maximizeGreatness(int[] nums) {\n    
\n\n# Complexity\n- Time complexity: $$O(n log n)$$ \n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int maximizeGreatness(int[] nums) {\n        Arrays.sort(nums);\n        int left=0,right=1,count=0;\n        while(right<nums.length)\n        {\n            if(nums[left]<nums[right])\n            {\n                left++;\n                right++;\n                count++;\n            }\n            else\n            {\n                right++;\n            }\n        }\n        return count;\n    }\n}\n```
['Java']