Calculate cumulative sum of array cArray [ 0 ] will store sum of zero elements
int [ ] cArray = new int [ n + 1 ] ; for ( i = 0 ; i < n ; i ++ ) cArray [ i + 1 ] = cArray [ i ] + arr [ i ] ; List < int > subArrSum = new List < int > ( ) ;