Trains the technique from
LeetCode 64Minimum Path SumThis 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 parcel sorting hall is laid out as a rectangular block of bays. You are given fees, where fees[r][c] is the handling fee charged by the bay standing in row r and column c. Fees are never negative and a free bay charges 0.
A parcel is dropped into the bay at row 0, column 0 and must leave from the bay in the final row and final column. From whichever bay the parcel is in, the belt can hand it one bay onwards along the same row, or one bay further down the same column. Nothing carries the parcel backwards along a row or back up a column.
Every bay the parcel passes through charges its fee, and that includes the bay it was dropped into and the bay it leaves from. Return the smallest total fee that any legal routing of the parcel can be billed at.
Example 1
Routing across the top two bays, then down the middle column and out gives 2 + 0 + 1 + 1 + 2 = 6, and no routing is billed less.
Example 2
Staying in the upper row until the final column and only then dropping down bills 1 + 3 + 1 + 2 + 1 = 8. Cutting down early runs into the bay charging 8.
Example 3
With a single bay the parcel is dropped in and leaves from the same bay, so its fee is billed once.
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_bay_route(fees: list[list[int]]) -> int:public int cheapestBayRoute(int[][] fees)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.