Skip to content

Practice Minimum Cost Path with Alternating Directions II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3603
LeetCode Problem

Minimum Cost Path with Alternating Directions II

Problem Statement

In an m by n grid, entering (i, j) costs (i + 1) * (j + 1). Start at (0, 0) at second 1 and pay its entry cost. At odd seconds, move right or down and pay the destination’s entry cost. At even seconds, wait and pay waitCost for the current cell. Stop immediately upon reaching the bottom-right cell, without another wait. Return the minimum total cost.

Source: Minimum Cost Path with Alternating Directions II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
m = 1, n = 2, waitCost = [[1,2]]
Output
3

# Example 2

Input
m = 2, n = 2, waitCost = [[3,5],[2,4]]
Output
9

# Example 3

Input
m = 2, n = 3, waitCost = [[6,1,4],[3,2,5]]
Output
16

Constraints

1 <= m, n <= 10^5
2 <= m * n <= 10^5
waitCost.length == m
waitCost[0].length == n
0 <= waitCost[i][j] <= 10^5

Related LeetCode Problems

Practice more problems similar to Minimum Cost Path with Alternating Directions II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.