Simplify directory path
MediumLet'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:
- Mutiple slashes like
///
is the same as a single slash/
- The two dots in
/../
implies looking at the parent directory - 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.Implement StackEasy
- 2.Implement QueueEasy
- 3.Max StackMedium
- 4.Valid ParenthesesMedium
- 5.Simplify PathMedium