Trains the technique from
LeetCode 1436Destination CityThis 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 courier's shift is written down as a list of legs. Entry legs[i] = [origin, arrival] records one leg driven from the depot named origin straight to the depot named arrival. The legs are jotted down in whatever order they were remembered, not in the order they were driven.
Taken together the legs form a single run that never returns to a depot it has already visited, so exactly one depot ends a leg without ever starting one.
Return the name of that depot, the stop where the run finishes. Depot names are compared character by character, so two names that differ only in letter case or in a space are different depots.
Example 1
Alder, Birch and Cedar each start a leg. Dune does not, so the run ends there.
Example 2
Wren and hollow each start a leg. Hollow with a capital H is a different depot and starts nothing, so the run ends there.
Example 3
Port Reed and Kiln End each start a leg, while Ash Row only ever ends one, so the run finishes at Ash Row.
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 final_stop(legs: list[list[str]]) -> str:public String finalStop(List<List<String>> legs)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.