Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
There will always be a way to make the prefix sum non-negative. How can we use that?
Loop over the array keeping the prefix sum. Whenever it goes negative, move the smallest number you have seen to the end.