Class Solution
java.lang.Object
g2501_2600.s2587_rearrange_array_to_maximize_prefix_score.Solution
2587 - Rearrange Array to Maximize Prefix Score.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You can rearrange the elements of <code>nums</code> to <strong>any order</strong> (including the given order).</p>
<p>Let <code>prefix</code> be the array containing the prefix sums of <code>nums</code> after rearranging it. In other words, <code>prefix[i]</code> is the sum of the elements from <code>0</code> to <code>i</code> in <code>nums</code> after rearranging it. The <strong>score</strong> of <code>nums</code> is the number of positive integers in the array <code>prefix</code>.</p>
<p>Return <em>the maximum score you can achieve</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,-1,0,1,-3,3,-3]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong></p>
<p>We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].</p>
<p>prefix = [2,5,6,5,2,2,-1], so the score is 6.</p>
<p>It can be shown that 6 is the maximum score we can obtain.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [-2,-3,0]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> Any rearrangement of the array will result in a score of 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>6</sup> <= nums[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxScore
public int maxScore(int[] nums)
-