TCP segment reassembly
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]) → strExamples
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.
0:00 of about 25 min
solution.py
InputExpectedGot
[[[0,"hel"],[3,"lo"]]]"hello"not run yetsample