Simplify Directory Path Problem Statement

You are provided with a directory path in Unix-style notation, and your task is to simplify it according to given rules.

In a Unix-style file system:

  • A dot (.) refers to the current directory.
  • A double dot (..) refers to the parent directory.
  • Multiple slashes between directories should be treated as a single slash.

The simplified path must start with a slash (/) and have single slashes between directory names without having a trailing slash.

Example:

Input:
T = 2
path = "/a/./b/../../c/"
path = "/home//foo/"
Output:
"/c"
"/home/foo"

Explanation:

For the given input paths, after applying the simplification rules, the resulting paths are shown in the output.

Constraints:

  • 1 <= T <= 100
  • 0 <= N <= 105 where N is the length of the input path.

Note that you do not need to print anything explicitly, as output formatting is handled. Just implement the function to return the simplified path.

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

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