bottom up approach to calculate score
function score ( n , A , k ) { if ( memo [ n ] [ k ] > 0 ) return memo [ n ] [ k ] ; let sum = 0 ; for ( let i = n - 1 ; i > 0 ; i -- ) { sum += A [ i ] ; memo [ n ] [ k ] = Math . max ( memo [ n ] [ k ] , score ( i , A , k - 1 ) + sum / ( n - i ) ) ; } return memo [ n ] [ k ] ; } function largestSumOfAverages ( A , K ) { let n = A . length ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += A [ i ] ;