calculating maximum sum subarrays in forward direction
fw [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ; max_so_far = Math . max ( max_so_far , cur_max ) ;