Tap here to switch tabs
Problem
Submissions

Problem: Make the Prefix Sum Non-negative

Make the Prefix Sum Non-negative asks you to reorder an integer array by moving elements to its end, using as few operations as possible so every prefix sum stays non-negative.

Statement

You are given an integer array nums indexed from 00. In one operation, you can choose any element of nums and move it to the end of the array.

Return the minimum number of operations required so that every prefix sum of nums is greater than or equal to 00.

Note: The test cases are generated such that it is always possible to make all prefix sums greater than or equal to 00.

Constraints:

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

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Make the Prefix Sum Non-negative

Make the Prefix Sum Non-negative asks you to reorder an integer array by moving elements to its end, using as few operations as possible so every prefix sum stays non-negative.

Statement

You are given an integer array nums indexed from 00. In one operation, you can choose any element of nums and move it to the end of the array.

Return the minimum number of operations required so that every prefix sum of nums is greater than or equal to 00.

Note: The test cases are generated such that it is always possible to make all prefix sums greater than or equal to 00.

Constraints:

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

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9