Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Greedy Number by kazuki.h
def greedy_number(line: str, length: int) -> str:
n = len(line)
if n == length:
return line
if length == 1:
return max(line)
M = max(line)
M_idx = line.index(M)
k = n - M_idx
return M+greedy_number(line[M_idx+1:], length-1) if k >= length else greedy_number(line[:M_idx], length-k) + line[M_idx:]
Nov. 25, 2021
Comments: