Kadane 's Algorithm to find Minimum subarray sum.
curr_min = Math . min ( curr_min + a [ i ] , a [ i ] ) ; min_so_far = Math . min ( min_so_far , curr_min ) ; } if ( min_so_far == sum ) return max_so_far ;