Simplify Directory Path

Given an absolute path for a file (Unix-style), simplify it.

Examples:

path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"

Note that absolute path always begin with ‘/’ ( root directory )
Path will not have whitespace characters.

Interview Code Editor
Hints
  • Solution Approach
  • Complete Solution
4712 successful submissions.
Asked In:
  • Microsoft
Click here to jump start your coding interview preparation