A deployment tool stores each artifact location as an absolute Unix-style path that always begins with /. The path may contain noise: repeated slashes (// counts the same as a single /), single-dot segments . (the current directory), and double-dot segments .. (the parent directory). Produce the canonical path:
. is dropped... removes the previous real directory name, if any; at the root, .. has no effect./ and, unless it is the root, never ends with a trailing /./.Directory names between slashes consist of lowercase letters and digits only (a name is never literally . or .. except when it is one of those special segments).
A single line: the path. It begins with / and contains no whitespace.
A single line: the canonical path.
/ and uses only /, lowercase letters, digits, and . characters.Example 1
Input
/usr//local/../bin
Expected
/usr/bin
Explanation
Splitting on slashes gives usr, local, .., bin (empty pieces from // are ignored). The .. removes local, leaving usr and bin, so the canonical path is /usr/bin.
Example 2
Input
/a/./b/../../c
Expected
/c
Explanation
Segments: a, . (dropped), b, .. (removes b), .. (removes a), c. Only c remains, giving /c.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →