Participate in Codex, Test Your Skills & Win BIG

Simplify Directory Path

Given a string A representing an absolute path for a file (Unix-style).

Return the string A after simplifying the absolute path.


  1. Absolute path always begin with ’/’ ( root directory ).

  2. Path will not have whitespace characters.

Input Format

The only argument given is string A.

Output Format

Return a string denoting the simplified absolue path for a file (Unix-style).

For Example

Input 1:
    A = "/home/"
Output 1:

Input 2:
    A = "/a/./b/../../c/"
Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Simplify Directory Path on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions