Normalize an absolute Unix-style file path by resolving . , .. , and redundant slashes.
Given an absolute path in Unix-style format, return its simplified canonical form.
The path may contain:
//...Rules:
. means stay in the current directory... means move up one directory, if possible./ and contain no trailing slash unless it is the root directory.Write a program that converts the given path into its canonical form.
path representing an absolute Unix-style path./.path is an absolute path.Example 1
Input
path = "/home/"
Output
"/home"
Explanation
The trailing slash is removed in canonical form.
Example 2
Input
path = "/a/./b/../../c/"
Output
"/c"
Explanation
./ stays in the current directory, and each .. moves up one level.
Example 3
Input
path = "/../"
Output
"/"
Explanation
At the root directory, .. cannot move above /.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.