Some entries in ans [ ] may not be filled yet . Fill them by taking values from right side of ans [ ]
for i in range ( n - 1 , 0 , - 1 ) : NEW_LINE INDENT ans [ i ] = max ( ans [ i ] , ans [ i + 1 ] ) NEW_LINE DEDENT