Sorting + Binary Search | C++
\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        int n = nums.size(), ans = 0, last = 0;\n        sort(nums.begin(), nums.en
```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        int n = nums.size(), ans = 0, last = 0;\n        sort(nums.begin(), nums.end());\n\n        for(int i=0; i<n; i++) {\n            int idx = lower_bound(nums.begin() + last + 1, nums.end(), nums[i] + 1) - nums.begin();\n            if(idx < n) {\n                last = idx;\n                ans++;\n            }\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Sorting', 'C++']