Simplify Directory Path

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


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
  • Solution Approach
  • Complete Solution
6298 successful submissions.
Asked In:
  • Microsoft
Click here to jump start your coding interview preparation