🔥Simplest Approach - Just One Loop One Condition🔥|| Sorting 🚀 || Step by Step Explanation ✅
\n# Approach\n1. Sort nums: Start by sorting nums. Let this sorted list be sorted_nums.\n2. Two-pointer Method:\n-> Initialize a pointer \uD835\uDC57 to track t
\n# Approach\n1. Sort nums: Start by sorting nums. Let this sorted list be sorted_nums.\n2. Two-pointer Method:\n-> Initialize a pointer \uD835\uDC57 to track the smallest element in sorted_nums that has not yet been matched.\n-> Loop over each element in sorted_nums with a second pointer \uD835\uDC56. If sorted_nums[i] (current element) is greater than sorted_nums[j], it means we have found a match where perm[j] > nums[j].\n-> Increment both pointers \uD835\uDC56 and \uD835\uDC57, and increase the count for each valid match.\n3. Return the Count: The count gives the maximum "greatness" as defined in the problem.\n\n# Complexity\n- Time complexity:\n\uD835\uDC42(\uD835\uDC5Blog\uD835\uDC5B) due to the sorting operation, where \uD835\uDC5B is the length of nums.\n\n\n\n- Space complexity:\n\uD835\uDC42(1) additional space (ignoring input space), as we only use a fixed amount of extra variables.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& n) {\n        vector<int> sn = n;\n\n        sort(sn.begin(), sn.end(), greater<int>());\n\n        int ans = 0;\n        int j = 0;\n        for(int i= 1; i<sn.size(); i++){\n           if( sn[i] < sn[j]){\n                ans++;\n                j++;\n           }\n        }\n        return ans;\n    }\n};\n```\n\nIf you found this solution helpful, please consider upvoting! \uD83D\uDE0A
['Sorting', 'C++']