Ezvor

2599. Make the Prefix Sum Non-negative

MediumArray Preparing judge… LeetCode
ArrayGreedyHeap (Priority Queue)

Hints

Hint 1
There will always be a way to make the prefix sum non-negative. How can we use that?
Hint 2
Loop over the array keeping the prefix sum. Whenever it goes negative, move the smallest number you have seen to the end.