Stack · Easy
A virtual-file browser receives absolute paths with repeated separators and relative navigation segments. It needs a stable display path. This is lexical normalization only: no filesystem access or symlink resolution is involved.
Return the canonical absolute path after resolving empty segments, dot segments and parent navigation.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
A JSON object { "path": string }.
Fields
- path is an ASCII string beginning with /. Segment names other than exactly . or .. are ordinary names.
Output
Return value
- Ignore empty and . segments. .. removes the most recent normal segment if one exists; it cannot go above root.
- Use one / between names and no final slash except at root.
- Preserve ordinary segment names exactly, including ... and case.
Constraints
- 1 <= path.length <= 100000. No filesystem or network calls.
- Percent-decoding, permissions, links and security access checks are outside this lexical task.
Examples
Example 1
{
"path": "/a//b/.././c/"
}Returns
"/a/c"b is removed by its following parent segment.
Example 2
{
"path": "/../../x"
}Returns
"/x"Parent segments at root do nothing.
Required complexity
O(path.length) time and space