Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach Every Position

Minimum Cost to Reach Every Position gives an array of costs and asks for an output array where each target records the least cost paid by choosing any index at or before it.

Statement

You are given an integer array cost of length n.

You want to reach every target position i from 00 to n −1- 1. To reach position i, you may choose any index j such that 0≤j≤i0 \leq j \leq i and pay cost[j].

Return an integer array ans of length n, where ans[i] is the minimum cost required to reach position i.

Constraints:

  • 1≤1 \leq n ==== cost.length ≤100\leq 100

  • 1≤1 \leq cost[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Reach Every Position

Minimum Cost to Reach Every Position gives an array of costs and asks for an output array where each target records the least cost paid by choosing any index at or before it.

Statement

You are given an integer array cost of length n.

You want to reach every target position i from 00 to n −1- 1. To reach position i, you may choose any index j such that 0≤j≤i0 \leq j \leq i and pay cost[j].

Return an integer array ans of length n, where ans[i] is the minimum cost required to reach position i.

Constraints:

  • 1≤1 \leq n ==== cost.length ≤100\leq 100

  • 1≤1 \leq cost[i] ≤100\leq 100