Parser and stack state: Normalize an absolute Unix-style path: ignore empty and . segments, let .. remove the previous normal segment without moving above root, and remove trailing slashes except for root.
Input: A JSON object { "path": string }.
Output: A JSON string containing the canonical absolute path.
Constraints:
- 1 <= path.length <= 100000
- path starts with /
- Segment names other than . and .. are preserved verbatim
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 12. 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