Find minimum number WHich have maximum length
for i in range ( maxi ) : NEW_LINE INDENT for j in range ( 1 , 10 ) : NEW_LINE INDENT if ( sum + arr [ pos ] - arr [ j - 1 ] >= 0 ) : NEW_LINE INDENT ans [ i ] = str ( j ) NEW_LINE sum += arr [ pos ] - arr [ j - 1 ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( maxi == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return " " . join ( ans ) NEW_LINE DEDENT