Trains the technique from
LeetCode 388Longest Absolute File 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.
A catalogue arrives as one string listing. Entries are separated by the newline character, and each entry is preceded by as many tab characters as its depth, so an entry at depth 0 has none, one at depth 1 has one, and so on. An entry at depth d + 1 sits inside the nearest earlier entry at depth d.
An entry whose name holds a dot is a crate, and every other entry is a shelf.
The route to an entry is the names from the outermost shelf down to the entry itself, joined by single / characters. Return the length of the longest route to a crate, or 0 when the catalogue holds no crate at all.
Example 1
The deeper crate's route joins three names with two slashes for sixteen characters, while the crate one level in gives only ten.
Example 2
The one entry holds no dot, so it is a shelf and the catalogue holds no crate at all.
Example 3
The single entry holds a dot, so it is a crate and its route is just its own name.
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 length_longest_path(listing: str) -> int:public int lengthLongestPath(String listing)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.