Medium · Stacks & Queues
Simplify Path
Given an absolute Unix-style path, return its simplified canonical path: a single leading slash followed by the remaining directory names separated by single slashes, where empty parts and "." are ignored and each ".." removes the previous name (doing nothing at the root).
Examples
Example 1
{
"path": "/a/./b/../../c/"
}Output: /c
Example 2
{
"path": "/home//foo/"
}Output: /home/foo
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.