Trains the technique from
LeetCode 3418Maximum Amount of Money Robot Can EarnThis 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 yard is laid out as coins. A cart starts at the top-left cell and finishes at the bottom-right, moving only one cell right or one cell down at a time.
Entering a cell adds its value to the haul, and a negative value is a toll. The cart carries two waivers; each may be spent on one cell it enters whose value is negative, and that cell then counts as nothing at all. Waivers may be left unused and cannot be spent on a cell whose value is not negative.
Return the largest haul the cart can finish with.
Example 1
Going right, right, down, down waives the tolls of 13 and 21 and collects 7, 4 and 8, coming to 19. No other route with two waivers does better.
Example 2
Every cell is a toll and every route enters three cells, so two of them are waived and the cheapest remaining toll is paid. Going down then right leaves the toll of 1 as the one to pay after waiving 3 and 4.
Example 3
The cart starts where it finishes, and the single cell is not a toll, so neither waiver is of any use.
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 maximum_amount(coins: list[list[int]]) -> int:public int maximumAmount(int[][] coins)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.