You are given a full path that starts with /.
Change it to the shortest clean path using these rules:
• . means stay in the same folder.
• .. means go up one folder (if possible).
• Many slashes // or /// count as one slash.
• Names like ... or .... are just normal folder names.
The final clean path must:
1. Start with one slash /.
2. Have folder names separated by one slash.
3. Not end with a slash unless it is just /.
4. Have no . or .. left.
Return this clean path.
Input: "/data/"
Output: "/data"
Explanation:
Remove the last slash.
Input: "/data//logs/"
Output: "/data/logs"
Explanation:
Many slashes become one.
Input: "/music/rock/../pop"
Output: "/music/pop"
Explanation:
".." goes up one folder.
Input: "/../"
Output: "/"
Explanation:
Already at root, cannot go higher.
Input: "/abc/.../x/../y/./"
Output: "/abc/.../y"
Explanation:
"..." is a normal folder name.
Accepted:
Submission: