TCP segment reassembly
Your task
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.
Examples
reassemble(segments: list[list]) -> strExample 1
Input
reassemble([[0, "hel"], [3, "lo"]])Output
"hello"