Skip to the code
cf.
+10 XP

#503 Cheapest Route Across a Latency Heatmap

easy

A network dashboard shows a heatmap of latencies as a grid, where grid[r][c] is the delay in milliseconds of passing through cell (r, c). A request enters at the top-left cell and leaves at the bottom-right cell, and at each step it moves one cell right or one cell down.

Write cheapestRoute(grid) that returns the smallest total delay of such a route, counting the first and the last cell.

Example 1

Input: grid = [[2,4,1],[1,6,1],[5,3,2]]
Output: 10

Right, right, down, down: 2 + 4 + 1 + 1 + 2.

Example 2

Input: grid = [[1,2,4],[3,5,6]]
Output: 13

Right, right, down: 1 + 2 + 4 + 6.

Constraints

  • 1 <= rows, cols <= 200
  • 0 <= grid[r][c] <= 100
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).