Code Room
CodingMediumcod-g1041
Subject Protocol tcp reassemblyLevel Mid–Senior~25 minCommon in Networking & APIs · Distributed systems interviewsIndustries Software development, Telecom

Question

Reassemble a byte stream from out-of-order TCP-style segments. You are given a list of [offset, data] segments where offset is the 0-based byte position and data is a string written starting at that offset. Segments may arrive out of order and may overlap; for any overlapping byte position the FIRST segment to cover it wins (later writes to an already-filled byte are ignored). Return the longest contiguous string starting at offset 0. If offset 0 is never written, return an empty string.

Implement
reassemble(segments: list[list]) → str
Examples
in[[[0,"hel"],[3,"lo"]]]out"hello"
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.