Simplify Path
Given a Unix-style absolute path, return its simplified canonical form.
Examples
Input: "/home/"
Output: "/home"
Input: "/a/./b/../../c/"
Output: "/c"
Hints
Use a stack to keep track of directories. Process each segment by pushing directories onto the stack and popping when encountering '..'.
Handle edge cases like multiple consecutive slashes, leading/trailing slashes, and ensure the root directory '/' is preserved correctly.
Optimize space by avoiding unnecessary stack operations for '.' and empty segments, and ensure the final path is constructed efficiently from the stack.
Related Problems
Simplify Path
Given a Unix-style absolute path, return its simplified canonical form.