Trains the technique from
LeetCode 3742Maximum Path Score in a GridThis 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 drives across a district laid out as m streets by n avenues. grid[i][j] is how many parcels are waiting at the corner on street i and avenue j. The depot sits at corner (0, 0) and has nothing waiting, and the sorting hall sits at corner (m - 1, n - 1).
From a corner the van may drive only to the next avenue, (i, j + 1), or to the next street, (i + 1, j). Whenever the van stands at a corner it must take every parcel waiting there, including at the depot and at the sorting hall, so a route's load is the total of the values of the corners it stands at.
The van's rack holds at most k parcels, so a route is drivable only when its load is at most k. Return the largest load of a drivable route, or -1 when every route from the depot to the sorting hall overloads the rack. A load is never negative, so -1 cannot be confused with a real load.
Example 1
Driving to the second street straight away and then along it stands at corners holding 0, 0, 0, 0 and 2 parcels, so that route loads 2 parcels and fits a rack of 3.
Example 2
There are only two routes across this district, and each of them stands at two corners holding 2 parcels, so each loads 4 parcels and neither fits a rack of 1.
Example 3
Driving along the first street to its end and then down the last avenue stands at corners holding 0, 2, 1, 0, 2, then 0 and 1, so that route loads 6 parcels and exactly fills the rack.
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 best_rack_load(grid: list[list[int]], k: int) -> int:public int bestRackLoad(int[][] grid, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.