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: MEDIUM. Variant: 20. Expect follow-up questions about complexity, edge cases, and alternative approaches.
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 medium difficulty.
The signed-in workspace provides the tools required by the