Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Cookie Monster by tokiojapan55
def cookie_monster(piles: list[int]) -> list[int]:
stack = [(piles, [], max(piles) + 1)]
while stack:
piles, eaten, limit = stack.pop(0)
for n in sorted(set(piles), reverse=True):
if n < limit:
piles2, eaten2 = [p if p < n else p - n for p in piles if p != n], eaten + [n]
if piles2 == []:
return eaten2
stack.append((piles2, eaten2, n))
Aug. 25, 2023
Comments: