Trains the technique from
LeetCode 71Simplify PathThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An artifact store addresses every folder with a locator that begins at the root, written as /. A locator is a run of pieces separated by /, and the store reads it like this:
. means stay where you are;.. means step back to the folder that contains the current one, and at the root it does nothing at all;..., which are ordinary names and not steps;// behaves exactly like /.The canonical form of a locator starts with /, puts exactly one / between consecutive folder names, and never ends with / unless it is the root by itself. Given path, return its canonical form.
Example 1
The doubled separator collapses to one and the trailing separator is dropped, leaving the two folder names in place.
Example 2
`.` leaves the position alone, the first `..` undoes `b` and the second undoes `a`, so only `c` is left below the root.
Example 3
`.._` is an ordinary folder name, so it is entered like any other, and the final `..` steps back out of it.
Example 4
A piece of three dots is a folder name, so the canonical form keeps it.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def simplify_path(path: str) -> str:public String simplifyPath(String path)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.