□ Robotics · dynamic programming
Cheapest path across a grid
Find the lowest energy route for a rover across a terrain grid, moving only right or down.
- Level 4 · Systems Engineer
- 6 tests
- 🐞 debug variant
- technically checked
Your task
A rover crosses a field divided into cells; each number is the energy (J) needed to cross that cell. It starts top-left, finishes bottom-right, and can only move right or down.
Write minPathCost(grid) returning the lowest total energy, counting the start and finish cells. An empty grid costs 0.
The trick (dynamic programming): the cheapest cost to reach a cell is its own cost plus the cheaper of the costs to reach the cell above it and the cell to its left.
Hints (0 of 3 shown)
What gets checked
- minPathCost([[1, 3, 1], [1, 5, 1], [4, 2, 1]]) → 7
- minPathCost([[5]]) → 5
Plus 4 hidden tests for edge cases. They run in the sandbox like the others; only the result is shown.
Tab indents · Esc then Tab leaves the editor · Ctrl/⌘ Enter runs · Ctrl/⌘ Shift Enter checks · Ctrl/⌘ / comments
Press Run to see what your program prints.
Your code runs only in this browser, inside an isolated sandbox with no network access, and stops after 3 s. Nothing you type is sent to Tactiverge; drafts and progress are saved in this browser only.