I have used the following algorithm for above problem
- Used Kadane’s algo. for finding the maximum sum of sub array.
- Then the latest index ( int latest ) at which the value of ‘current count’ became zero .
loop goes from j=0 to j<latest…and follow the Kadane’s algorithm .
for( int j = 0; j < latest ; j++ )
{
Kadane's algo..
}