31/40
Part 6 of 7 · The worked exampleLearn and do

Two one-line bugs: inserting first, and testing with get

The order of the two lines in the loop matters. Check before you insert. Insert first, and a file can pair with itself. With [750, 100]:

StepInsert, then checkCheck, then insert
j = 0seen: 750 → 0. Need 750: in seen, at 0need 750: not in seen. seen: 750 → 0
j = 1already returned (0, 0), wrongneed 1400: not in seen. seen: 750 → 0, 100 → 1
endreturn None

Checking first returns None there. It returns (0, 2) for [750, 100, 750]: two different files of the same size.

Test membership with in. if seen.get(need): reads the stored position as true or false, and position 0 is false. On [700, 250, 800] that version returns None instead of (0, 2).

Test the edges you named too: [] and [1500] both return None.

In the editor, fill_exactly has both bugs. Run it: [700, 250, 800] should give (0, 2). Fix the loop so that it checks before it inserts, and tests with in.