Greedy
151 / 170GreedyLesson 5 of 9About 43 min
The strongest kind of greedy argument: the choice is not best, it is the only one available.
Given a multiset that must be split into runs of consecutive values, the smallest remaining value is examined. Type the three lines it prints.
from collections import Counter counts = Counter([1, 2, 3, 2, 3, 4])size = 3value = min(counts) print("smallest remaining:", value)print("could it sit in the middle of a run?", counts[value - 1] > 0)print("so it must start one, needing:", [value + offset for offset in range(size)])Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.