Simplify the Directory

You are given a path to a file/directory in Unix-style of length N, In a Unix-style file system, a dot(.) refers to the current directory. A double dot(..) refers to the previous directory in reference to the current directory. If there are multiple slashes between two directories you should consider it as a single slash.

Now, for a given directory path as a string, you are required to simplify the same and tell the final destination in the directory structure or the path.

The simplified path should always begin with a slash(/) and there must be a single slash between two directory names. There should not be a trailing slash.

Input Format :
The first line contains an integer T which denotes the number of test cases to be run. 

The first and only line of each testcase contains a single string denoting the path .
Output Format:
For each test case, print a string representing a simplified path to the resulting file or directory.
Note:
You are not required to print anything explicitly. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 100
0 <= N <= 10^5
Where N is the length of the input path.

Time Limit : 1 sec
AnswerBot
1y

The task is to simplify a given Unix-style directory path and determine the final destination.

  • Replace multiple slashes with a single slash

  • Handle dot (.) by ignoring it

  • Handle double dot (..) by removin...read more

Help your peers!
Add answer anonymously...
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter