Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Simplify path and Clone graph



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Path Normalization Problem

Path Normalization

Problem Statement

Given a full path to a file or directory in a Linux-like system, your task is to convert it into a standardized path.

In this system, a single dot . points to the current directory, and two dots .. mean moving one directory up. The simplified path should always start with a slash /, with only one slash separating directory names. The path should not end with a slash unless it is the root directory. The result should be the shortest possible absolute path representing the same location.

Examples

Input: "/user/"
Output: "/user"
Explanation: The final path does not have a trailing slash after the directory name.
    
Input: "/../../"
Output: "/"
Explanation: Trying to go above root directory stays at root.
    
Input: "/user//docs/"
Output: "/user/docs"
Explanation: Multiple slashes are replaced by a single slash.
    
Input: "/x/./y/../z/"
Output: "/x/z"
    
Input: "/x/../../y/../z//./"
Output: "/z"
    
Input: "/x//y////z/w//././/.."
Output: "/x/y/z"
    

Constraints

  • The input path string length is between 1 and 5000 characters.
  • The path consists only of English letters, digits, periods ., slashes /, and underscores _.