TCP stream reassembly
Your task
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 ''.
Examples
reassemble_segments(segments: list[list]) -> strExample 1
Input
reassemble_segments([[0, "hello"], [5, "world"]])Output
"helloworld"