Minimum Cost With Broken Stairs

Given step costs and a list of broken steps that cannot be used, return the minimum cost to reach the top using 1 or 2 step jumps. Pattern focus: Min cost climbing. This adds blocked states and forces you to skip invalid transitions.

Input Format

cost = cost of each step, broken = forbidden step indices

Output Format

minimum total cost to reach the top, or -1 if impossible

Constraints

  • 2 <= cost.length <= 10^5; 0 <= broken.length <= cost.length; broken indices are distinct and valid

Examples

Example 1:

Input:

cost = [1,100,1,1]
broken = [1]

Output:

2

Explanation:

The cheapest valid route avoids the broken step 1.

Example 2:

Input:

cost = [5,1,2,10,1]
broken = [2]

Output:

11

Explanation:

The best valid route passes through the cheaper reachable steps.

Loading...
Minimum Cost With Broken Stairs - Dp 1d