Unix Path Simplifier
HardAcc. 82.1%
+45 XP 20
Canonical Logic
Unix paths use .. to go up a level and . for current. A stack helps "track" current directory depth.
The Assignment
Your function receives path.
- Split the path by
/. - Iterate through parts:
- If ".." and stack not empty, pop.
- If valid name (not "" or "."), push.
- Print the joined path starting with
/.
01EXAMPLE 1
Input
path="/home//foo/"Output
/home/fooExplanation: Double slash ignored.
Constraints
- Final path must not have trailing slash.
Data StructuresStack
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
path"/home/"
Expected Output
/home
Click RUN to test your solution