Loop to iterate over every possible subarray of the array
for ( let i = 0 ; i < n - 1 ; i ++ ) { let tmpsum = arr [ i ] ; for ( let j = i + 1 ; j < n ; j ++ ) { tmpsum += arr [ j ] ; if ( tmpsum <= n ) { ans += freq [ tmpsum ] ; freq [ tmpsum ] = 0 ; } } } return ans ; }