2592. Maximize Greatness of an Array
2592. Maximize Greatness of an Array
Description
You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.
We define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].
Return the maximum possible greatness you can achieve after permuting nums.
Example 1:
1 | Input: nums = [1,3,5,2,1,3,1] |
Example 2:
1 | Input: nums = [1,2,3,4] |
Constraints:
1 <= nums.length <= 10^50 <= nums[i] <= 10^9
Hints/Notes
- 2025/03/29 Q3
- two pointers, check 0x4F’s hash solution
- 0x3F’s solution
Solution
Language: C++
1 | class Solution { |