We have an array having n integers whose sum is non negative.
I need to prove that there exists an index i, such that starting from i, all prefix sums are non negative, till we reach i again circularly.
Say the array is a1, a2, a3, ..... , an, such that a1 + a2 + a3 + ..... + an>=0.
So we need to prove that for some index i, all prefix sums are non-negative, i.e,
ai >= 0,
ai + ai+1 >=0,
ai + ai+1 + ai+2 >=0
.
.
ai + ai+1 + ... + an + a1 + .... + ai-1 >=0
I need this for the following question, https://www.interviewbit.com/problems/gas-station/. Though I've already used the above statement in the solution of this question, but I am still not able to prove it.