Computing the previous sum
if ( i < K ) : NEW_LINE INDENT arr [ i + 1 ] = arr [ i ] + prevsum ; NEW_LINE prevsum = arr [ i + 1 ] ; NEW_LINE DEDENT else : NEW_LINE INDENT arr [ i + 1 ] = arr [ i ] + prevsum - arr [ i + 1 - K ] ; NEW_LINE prevsum = arr [ i + 1 ] ; NEW_LINE DEDENT