Loading
Loading
A warehouse robot drives from the loading dock in the top-left cell of the floor to the packing station in the bottom-right cell. Every cell has a congestion delay in seconds, and the robot pays the delay of every cell it occupies, including the first and the last.
The robot can only move one cell right or one cell down at a time. Return the smallest total delay of any route.
grid = [[2, 7, 1], [3, 1, 4], [6, 2, 1]]row 0: 2 9 10only reachable from the leftrow 1: 5 6 106 = 1 + min(9, 5)row 2: 11 8 99 = 1 + min(10, 8)route 2 → 3 → 1 → 2 → 1down, right, down, right9Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
| 0 | 2 | 7 | 1 |
|---|---|---|---|
| 1 | 3 | 1 | 4 |
| 2 | 6 | 2 | 1 |
2, 3, 1, 2, 1 (down, right, down, right) totals 9.
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(rows × cols) time · O(cols) space
Input. Run your code to watch it work on this input, one line at a time.
| 0 | 2 | 7 | 1 |
|---|---|---|---|
| 1 | 3 | 1 | 4 |
| 2 | 6 | 2 | 1 |
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
| 0 | 5 | 1 |
|---|---|---|
| 1 | 1 | 5 |
Both routes pass one of the 5s: 5 + 1 + 5 or 5 + 1 + 5.