 All Problems
Simplify Path
medium
strings
stack
amazon
google
microsoft
facebook

Given an absolute Unix file path, convert it to its simplified canonical form.

Rules: multiple slashes → single slash; '.' stays in current dir; '..' goes up one dir; result must start with '/'.

Example 1:

Input: /home//foo/
Output: /home/foo

Example 2:

Input: /home/user/Documents/../Pictures
Output: /home/user/Pictures

Input format: Unix-style path string.

Output format: Simplified canonical path.

Run to check your code against the sample cases, or submit to run every case