Class Solution
java.lang.Object
g2501_2600.s2592_maximize_greatness_of_an_array.Solution
2592 - Maximize Greatness of an Array.<p>Medium</p>
<p>You are given a 0-indexed integer array <code>nums</code>. You are allowed to permute <code>nums</code> into a new array <code>perm</code> of your choosing.</p>
<p>We define the <strong>greatness</strong> of <code>nums</code> be the number of indices <code>0 <= i < nums.length</code> for which <code>perm[i] > nums[i]</code>.</p>
<p>Return <em>the <strong>maximum</strong> possible greatness you can achieve after permuting</em> <code>nums</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,5,2,1,3,1]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> One of the optimal rearrangements is perm = [2,5,1,3,3,1,1]. At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> We can prove the optimal perm is [2,3,4,1]. At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximizeGreatness
public int maximizeGreatness(int[] nums)
-