Code Room
CodingMediumcod-g1153
Subject Networking protocolsLevel Mid–Senior~25 minCommon in Networking & APIs interviewsIndustries Telecom, Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.