Medium data structure and algorithm practice puzzle.
Given segment numbers in the order they arrive and the number expected first, return how many segments can be delivered in order by the end. The network reorders freely, so a segment that arrives early has to wait in a buffer until the gap in front of it is filled, and then a whole run may become deliverable at once. Duplicates arrive too and must not be counted twice. The same problem is in this site's co-op board: placements arrive out of order and only apply in order.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Browse all 536 puzzles