🔥💯Best Solution in C++ || BinarySearch✅ || Sorting💯
Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1
#### Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n## Please Upvote if u liked my Solution\uD83E\uDD17\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        int n=nums.size(),ind=0,count=0;\n        for(int i=0;i<n;i++){\n            auto ub=upper_bound(nums.begin()+ind+1,nums.end(),nums[i]);\n            if(ub!=nums.end()){\n                count++;\n                ind=ub-nums.begin();\n            }\n            else\n                break;\n        } \n        return count;\n    }\n};\n```\n![image.png](https://assets.leetcode.com/users/images/7a18ee27-13e3-41c8-825c-6ceec830ef7d_1679158054.494318.png)\n
['Binary Search', 'Greedy', 'Sorting', 'C++']