#3603
Minimum Cost Path with Alternating Directions II
specialist · 960 · lc medium +32 · 44.6% accepted · 72 likes · top 27%
Description
A grid has m rows and n columns. Entering cell (i, j) costs (i + 1) * (j + 1). A second array waitCost[i][j] gives the cost of waiting at that cell.
You enter (0, 0) on second 1, paying its entry cost. Movement alternates:
- On odd seconds: move right or down to an adjacent cell and pay its entry cost.
- On even seconds: remain in place for one second and pay waitCost[i][j].
Return the minimum total cost to reach (m - 1, n - 1).
Code
1
2
3