48. Simplify Absolute Path
Interpret repeated separators, current-directory components, and parent-directory components to produce a normalized absolute path. The result describes the same lexical location under these path rules.
A parent traversal cannot move above the root. This is lexical path processing, not filesystem access or symbolic-link resolution.
Example 1
Input
"/a//b/../c/./"
Output
"/a/c"
Explanation: Ignore empty/dot components and cancel b with its following parent traversal.
Example 2
Input
"/../../.../x"
Output
"/.../x"
Explanation: Root parents stay at root; ... is a literal directory name.
Constraints
1 <= path.length <= 105- path begins with / and contains no NUL character. Slash is the only separator.
Hints
Hint 1
What does one parent component undo in the processed path?
Hint 2
Which names are special only by exact equality?
Hint 3
Build canonical components, clamp parents at root, and join once.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Canonical components survive only meaningful operations
"/a//b/../c/./"
"/a/c"