Trains the technique from
LeetCode 120TriangleThis 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 drift monitor prints its readings as a growing stack of rows. Row 0 holds one reading,
and every later row holds exactly one more reading than the row above it, so row i holds
i + 1 readings. Each reading is a signed drift in millidegrees and may be negative.
A trace begins on the single reading in row 0 and ends on some reading in the last row.
From reading j of row i, a trace may continue to reading j or to reading j + 1 of
row i + 1. The weight of a trace is the sum of every reading it lands on, including the
first and the last.
Given rows, return the smallest weight any trace can have.
Example 1
The trace 3 -> 7 -> 0 starts on the only reading of row 0, moves to reading 1 of row 1 and then to reading 2 of row 2, so every hop is allowed. Its readings add to 10.
Example 2
The trace 2 -> -3 -> -1 -> -6 keeps to indices 0, 1, 1, 2, and each hop either holds the index or raises it by one. The four readings add to -8.
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 cheapest_cascade(rows: list[list[int]]) -> int:public int cheapestCascade(List<List<Integer>> rows)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.