Trains the technique from
LeetCode 3651Minimum Cost Path with TeleportationsThis 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 a grid grid, and grid[r][c] is the toll charged for entering that square. A trolley starts on the top-left square and must reach the bottom-right one. The starting square costs nothing.
Two kinds of move are available:
k hops may be made in total.Return the smallest total toll for getting from the top-left square to the bottom-right one.
Example 1
No hops are allowed, so only the order of the steps is open. Going right and then down pays 2 and then 4, which beats going down and then right.
Example 2
The starting square carries the highest toll on the yard, so one hop can land anywhere at all, the far corner included, for nothing.
Example 3
No square carries a toll as high as the far corner, so no hop can land on it. Instead hop from the start onto the square beside it, free because both carry 5, and then step in and pay the corner's 100.
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 min_cost(grid: list[list[int]], k: int) -> int:public int minCost(int[][] grid, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.