Where cd Lands
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
docs goes into /home/kim/docs, ../pics goes up and into pics, and ./cats goes into cats.
Example 2
Three .. moves climb to the root (the third one has no effect), then c goes down.
Constraints
startand every move have at most 40 characters0 <= len(moves) <= 20- folder names are 1 to 6 lowercase letters; no path has two slashes in a row or a trailing slash, apart from the root
/itself
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Balanced Outside QuotesMedium
- Browser Back and ForwardMedium
- Convoys at the GateMedium
- Daily TemperaturesMedium
- Decode StringMedium
- Flip and Double BracketsMedium
- Keep the Digits, One of Each LetterMedium
- Largest Open PlotMedium