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
4mo

Given a Unix-style directory path, simplify it by following certain rules and return the simplified path.

  • Use a stack to keep track of directories while iterating through the input path.

  • Handle cases fo...read more

Help your peers!
Select
Add answer anonymously...

Goldman Sachs Software Engineer interview questions & answers

A Software Engineer was asked 3mo agoQ. How do we make money?
A Software Engineer was asked Q. How do you create a BST from an incoming stream of nodes?
A Software Engineer was asked Q. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more

Popular interview questions of Software Engineer

A Software Engineer was asked 3mo agoQ1. How do we make money?
A Software Engineer was asked Q2. How do you create a BST from an incoming stream of nodes?
A Software Engineer was asked Q3. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more
Goldman Sachs Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits