FunctionRacerProblemsRace

Simplify Path

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

path is an absolute file path that starts with /. Simplify it:

Return the simplified path: it starts with /, folder names are separated by a single /, and there is no trailing / (except for the root path / itself).

Example 1

path "/home//foo/"
returns "/home/foo"

/home/foo.

Example 2

path "/a/./b/../../c/"
returns "/c"

Goes into a, b, back out twice, then c: /c.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems