Beats 💯% Time and Space
\n\n# Approach\n Describe your approach to solving the problem. \nWe\'ll use 2-pointer approach and will compare the elements.\n\n---\n\n# Complexity\n- Time co
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe\'ll use 2-pointer approach and will compare the elements.\n\n---\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(nlog(n))$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n---\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        int n = nums.size();\n        if(n==1) return 0;\n        int count = 0;\n        \n        sort(nums.begin(), nums.end());\n        int p1 = 0, p2 = 1;\n        \n        while(p2!=n){\n            if(nums[p1]<nums[p2]){\n                count++;\n                p1++;\n                p2++;\n            }\n            else{\n                p2++;\n            }\n        }\n        return count;\n    }\n};\n```\n\n---\n\n<p align="center">\n<img src="https://assets.leetcode.com/users/images/7bf798d7-29ee-4abf-aa93-dd873f8c9546_1675560239.9938114.jpeg" alt="">\n</p>
['Array', 'Two Pointers', 'C++']