path, return its canonical form. Rules: a single slash separates directories, a trailing slash is dropped, "." refers to the current directory (ignore it), and ".." moves up one directory. The canonical path always starts with "/".Simplify a Filesystem Path
L4 Easy Stack
Concept
Filesystem paths can be simplified with a stack: split on "/", skip empty pieces and ".", and treat ".." as a pop.
Given an absolute Unix-style path
Examples
▸ path = "/home/"
→ /home
▸ path = "/../"
→ /
▸ path = "/a/./b/../../c/"
→ /c
Progressive Hints
Hint 1 · Nudge
Split into pieces and let a stack keep only the directories that survive '..'.
Hint 2 · Plan
Split the path by '/'. For each piece: ignore empty pieces and '.'. For '..', pop the last directory if there is one. Otherwise push the piece as a directory. Join the stack with '/' and prefix it with '/'.
Hint 3 · Approach
stack = []. For each part in path split by '/': if part is empty or '.', skip; if part is '..', pop when non-empty; otherwise push part. Return '/' plus the stack joined by '/'.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.