Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Array to Maximize Prefix Score

med
30 min
Try to solve the Rearrange Array to Maximize Prefix Score problem.

Statement

Given an integer array nums, you can rearrange its elements in any arbitrary order.

Let prefix be an array containing the prefix sums of nums, where prefix[i] equals the sum of all elements from nums[0] through nums[i] for each index i.

The score of the rearranged array is defined as the total number of strictly positive values in the array prefix.

Return the maximum score achievable after optimally rearranging nums.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Array to Maximize Prefix Score

med
30 min
Try to solve the Rearrange Array to Maximize Prefix Score problem.

Statement

Given an integer array nums, you can rearrange its elements in any arbitrary order.

Let prefix be an array containing the prefix sums of nums, where prefix[i] equals the sum of all elements from nums[0] through nums[i] for each index i.

The score of the rearranged array is defined as the total number of strictly positive values in the array prefix.

Return the maximum score achievable after optimally rearranging nums.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6