bottom up approach to calculate score
def score ( n , A , k ) : NEW_LINE INDENT if ( memo [ n ] [ k ] > 0 ) : NEW_LINE INDENT return memo [ n ] [ k ] NEW_LINE DEDENT sum = 0 NEW_LINE i = n - 1 NEW_LINE while ( i > 0 ) : NEW_LINE INDENT sum += A [ i ] NEW_LINE memo [ n ] [ k ] = max ( memo [ n ] [ k ] , score ( i , A , k - 1 ) + int ( sum / ( n - i ) ) ) NEW_LINE i -= 1 NEW_LINE DEDENT return memo [ n ] [ k ] NEW_LINE DEDENT def largestSumOfAverages ( A , K ) : NEW_LINE INDENT n = len ( A ) NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += A [ i ] NEW_LINE DEDENT DEDENT