Explanation Using Sorting
🚀 Approach
The approach is very simple and straight-forward , we can just sort the array and then traverse through it once.
The function of the while loop here
# 🚀 Approach 
* The approach is very simple and straight-forward , we can just sort the array and then traverse through it once.
* The function of the while loop here is that it increments `j` until it points to the first element in the sorted array that is strictly greater than `nums[i]`.
Essentially, it ensures that `nums[j] > nums[i]` before pairing `nums[j]` with `nums[i]`.

```cpp []
class Solution {
public:
    int maximizeGreatness(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int cnt = 0;
        int j = 0; 
        for (int i = 0; i < nums.size(); i++) {
            while (j < nums.size() && nums[j] <= nums[i]) {
                j++;
            }
            if (j < nums.size()) {
                cnt++;
                j++; 
            }
        }
        return cnt;
    }
};
```
['Sorting', 'C++']