Dodomeki
Sign in

54. Lowest-Cost Crossing

Easy

You are given a rectangular grid custos, where each cell contains a non-negative cost. Starting at the top-left corner, you may move only one cell to the right or one cell down at each step.

Return the minimum total cost to reach the bottom-right corner. The sum includes the costs of both the starting and ending cells.

Example 1
Input: custos = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: A minimum-cost route adds 1 + 3 + 1 + 1 + 1.
Example 2
Input: custos = [[2,0,3,1]]
Output: 6
Explanation: In a single row, the route must pass through every cell.
Constraints
  • 1 <= custos.length <= 100
  • 1 <= custos[i].length <= 100
  • custos has the same number of columns in every row.
  • 0 <= custos[i][j] <= 1000
Dynamic programmingMatrix
Caso 1
custos =
[[1,3,1],[1,5,1],[4,2,1]]
Expected =
7
Caso 2
custos =
[[2,0,3,1]]
Expected =
6

Run checks these 2 cases. Submit runs all 10, including hidden ones.