Intervals: Merge all overlapping or touching closed intervals and return the merged intervals ordered by start, then end.
Input: A JSON object { "intervals": [number, number][] } where each pair is [start, end].
Output: A JSON array of non-overlapping [start, end] pairs.
Constraints:
- 0 <= intervals.length <= 100000
- Every interval satisfies start <= end
- Intervals are closed, so [1,2] and [2,3] merge
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 6. Favor a pragmatic solution that is easy to ship, read, and adapt.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked hard difficulty.
The signed-in workspace provides the tools required by the round, such as recordin