Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

A data pipeline reconstructs a long string from ordered segments. You are given an array segments where each element is an array of three strings [startId, endId, payload]. The startId and endId mark the two endpoints of the segment, and payload is the string fragment it contributes.

The segments form a single directed chain: one segment's endId equals the next segment's startId. startId values are unique among all segment starts, and endId values are unique among all segment ends, but the same ID may appear as one segment's endId and another segment's startId.

Given the segments in any order, reconstruct the original string by concatenating the payloads in chain order.

Test Cases
Input
Output
Expected