2599. Make the Prefix Sum Non-negative
You are given a 0-indexed integer array
nums
. You can apply the following operation any number of times:
- Pick any element from
nums
and put it at the end ofnums
.The prefix sum array of
nums
is an arrayprefix
of the same length asnums
such thatprefix[i]
is the sum of all the integersnums[j]
wherej
is in the inclusive range[0, i]
.Return the minimum number of operations such that the prefix sum array does not contain negative integers. The test cases are generated such that it is always possible to make the prefix sum array non-negative.
1 | class Solution { |