Give an Array of integers eg : 10, -10, -1, -1, 10 . I have to find minimum reallocations such that all the prefix sums of the array are >=0. The sum of all elements in the array
is assumed to be non-negative. In the above example, we can move -10 to the end of the array to make all prefix sum positive. Not sure how to approach this problem efficiently. Where taking a number and inserting it anywhere else is to be treated as one reallocation.
The problem is to be solved for one more type of reallocation :
- Any negative number can be moved to the end of the array