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

6 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.Valid stack sequenceMedium
  4. 4.Max StackMedium
  5. 5.Valid ParenthesesMedium
  6. 6.Simplify PathMedium