Simplify a Unix Path
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write simplifyPath(path): path is an absolute Unix path that starts with "/". Return its simplest form. A "." means the current folder and is dropped; ".." goes up to the parent folder, and at the root it stays there; several slashes in a row count as one. Any other name, even "..." or "..a", is a folder name. The result starts with a single "/", joins names with single slashes and has no slash at the end, except "/" on its own for the root. For example, simplifyPath("/a/./b/../../c/") is "/c".
Your code must pass
- Joins folder names with single slashes
- Drops . and goes up for ..
- Never goes above the root
- Keeps other names made of dots