Code RoomTCP stream reassembly
MediumPrep Room Coding #326

TCP stream reassembly

CodingNetworking & APIsMid–Senior~25 min

Reassemble a TCP byte stream from received segments. Each segment is [seq, data] where seq is the absolute byte offset of the first character of 'data'. Segments may arrive out of order and may overlap (when bytes overlap, the first-written byte wins). The stream begins at the smallest seq present. Return the longest contiguous prefix of the reassembled stream starting at that first byte, stopping at the first missing byte (gap). For empty input, return ''.

Implement
reassemble_segments(segments: list[list]) → str
Examples
in[[[0,"hello"],[5,"world"]]]out"helloworld"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[[0,"hello"],[5,"world"]]]"helloworld"not run yetsample