24/34
Part 6 of 7 · The worked exampleLearn and do
A worked example: rebuild the free runs from a dump
Clarify first: blocks may touch, and an overlap or a block past the end is corrupt
The prompt: a server crashed, and its dump lists the live blocks of an arena of size units as (start, n) pairs, in no particular order. Return the free runs, half-open and in order. If the dump is corrupt, with two blocks that overlap or a block that runs past the arena, raise ValueError. Here size = 100:
DUMP = [(40, 10), (0, 15), (15, 5), (70, 30), (52, 8)]
print(sorted(DUMP))
[(0, 15), (15, 5), (40, 10), (52, 8), (70, 30)]
Size 100. Live blocks (0, 15), (15, 5), (40, 10), (52, 8), (70, 30), as (start, n). What are the free runs?
Pick an answer above to see the rest