Practice Simplify Path
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Convert an absolute Unix path to its canonical form. Treat repeated slashes as one separator, ignore a component equal to ., and use .. to move to the parent directory without moving above the root. Other component names are literal, including ... and ..... The result begins with one slash, uses one slash between retained components, and has no trailing slash unless the result is the root /.
Source: Simplify Path on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
path = "/home/"
"/home"
# Example 2
path = "/home//foo/"
"/home/foo"
# Example 3
path = "/home/user/Documents/../Pictures"
"/home/user/Pictures"
# Example 4
path = "/../"
"/"
# Example 5
path = "/.../a/../b/c/../d/./"
"/.../b/d"
Constraints
Related LeetCode Problems
Practice more problems similar to Simplify Path.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.