Stack Bash - Master data structures and algorithms

Simplify directory path

Medium
Let's say you're given a dirty directory path:
/usr/root/../sbin/./../documents
The simplified version of the above path is the following:
/usr/documents
Write a function that accepts a dirty directory path and returns the simplified version.
The directory path can be cleaned using the following rules:
  1. Mutiple slashes like /// is the same as a single slash /
  2. The two dots in /../ implies looking at the parent directory
  3. A single dot like /./ implies to stay in the current path.

Try it

Solution

5 Essential Stacks & Queues Coding Interview Problems

Master Stacks & Queues by trying the coding challenges below.
  1. 1.Implement StackEasy
  2. 2.Implement QueueEasy
  3. 3.Max StackMedium
  4. 4.Valid ParenthesesMedium
  5. 5.Simplify PathMedium

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.