Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Beat The Previous by kavishhh
def beat_previous(digits: str) -> list[int]:
# your code here
res = []
i = 0
n = len(digits)
if n == 0:
return res
current = int(digits[0])
res.append(current)
i = 1
while i < n:
next_num = None
for j in range(i + 1, n + 1):
candidate = int(digits[i:j])
if candidate > current:
next_num = candidate
i = j
break
if next_num is None:
break
res.append(next_num)
current = next_num
return res
print("Example:")
print(beat_previous("123"))
# These "asserts" are used for self-checking
assert beat_previous("600005") == [6]
assert beat_previous("6000050") == [6, 50]
assert beat_previous("045349") == [0, 4, 5, 34]
assert beat_previous("77777777777777777777777") == [7, 77, 777, 7777, 77777, 777777]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 29, 2025