Trains the technique from
LeetCode 104Maximum Depth of Binary TreeThis 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 survey charts a river delta as junctions that split the flow downstream. Each junction sends water onward through at most two channels, one toward the west bank and one toward the east bank, and each junction records a signed bed grade in centimetres per kilometre.
The chart arrives as junctions, a listing that walks the delta one tier at a time starting at the source, with the west entry of a tier written before its east entry. Slot 0 holds the source junction. Every junction that appears in the listing claims the next two free slots, its west channel first and its east channel second. A slot holding null means no channel leaves in that direction, and such a slot claims no slots of its own. Trailing null slots may be left off, and an empty listing means nothing was charted.
A run begins at the source junction, follows channels downstream only, and halts at a junction that sends water nowhere. Report how many junctions sit on the longest run. When nothing was charted, report 0.
Example 1
The source splits west into -5 and east into 40. The junction -5 sends water east into 7, so the longest run visits three junctions while the run through 40 visits only two.
Example 2
Nothing was charted, so no run exists and the answer is zero.
Example 3
The source sends water nowhere, so the only run halts immediately after visiting one junction.
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 delta_run_length(junctions: list[int | None]) -> int:public int deltaRunLength(Integer[] junctions)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.