Stores the prefix sums
let prefix_sum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;