Trains the technique from
LeetCode 329Longest Increasing Path in a MatrixThis 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 container yard is laid out as a rectangular grid of bays. heights[r][c] is how many containers are stacked in the bay at row r, column c.
A gantry inspector walks the yard bay by bay. From a bay the inspector may step to a bay sharing an edge with it, up, down, left or right, and only if that bay's stack is strictly taller than the one just left. Diagonal steps are not possible, and the walk may not leave the yard.
The inspector picks the starting bay. Return the greatest number of bays a single walk can cover, counting the starting bay itself.
Example 1
Starting at the bay holding 1 the inspector can reach 2, then 4, then 5, then 9, covering five bays. No walk covers six.
Example 2
Every stack is the same height, so no step is ever allowed and the walk is the starting bay on its own.
Example 3
From 2 the inspector goes to 3, then down to 4, then left to 5, covering four bays. The route through 6 and 7 also stops at four.
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 longest_ascent(heights: list[list[int]]) -> int:public int longestAscent(int[][] heights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.