Check the algorithm

I have used the following algorithm for above problem

  1. Used Kadane’s algo. for finding the maximum sum of sub array.
  2. 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..
 }

Just apply simple kadane on array B. Here array B is array A concatenated to itself.