FunctionRacerProblemsRace

Where cd Lands

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

You start in the folder start, given as an absolute path such as /home/kim (the root alone is /). Then you run the cd commands in moves one after another. Each move is a path whose parts are separated by /: a move that starts with / is absolute and begins again from the root, any other move is relative to where you are. Within a move, .. goes up one folder (at the root it does nothing), . stays where you are, and any other name goes down into that folder.

Return the absolute path of the folder you end up in: it starts with /, its folder names are separated by single slashes, and it has no slash at the end unless it is the root /.

Example 1

start "/home/kim"
moves ["docs","../pics","./cats"]
returns "/home/kim/pics/cats"

docs goes into /home/kim/docs, ../pics goes up and into pics, and ./cats goes into cats.

Example 2

start "/a/b"
moves ["..","..","..","c"]
returns "/c"

Three .. moves climb to the root (the third one has no effect), then c goes down.

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