Traverse original array and compute cumulative sum and increase count by 1 for this sum in ' um ' . Adds ' - 1' when arr [ i ] == 0
for ( var i = 0 ; i < n ; i ++ ) { curr_sum += ( arr [ i ] == 0 ) ? - 1 : arr [ i ] ; if ( um . has ( curr_sum ) ) um . set ( curr_sum , um . get ( curr_sum ) + 1 ) ; else um . set ( curr_sum , 1 ) } var count = 0 ;