Compute the minimum cost needed to reach every position in an array or sequence from a starting point under the problem's movement rules.
You are given a sequence of positions and a rule for moving between them with an associated cost. Starting from an initial position, determine the minimum cost required to reach every reachable position.
The exact movement constraints may vary by platform formulation, but the core task is the same: for each position, choose the cheapest valid way to arrive there from earlier reachable positions.
A typical solution uses dynamic programming or a shortest-path-like relaxation over the array, since each position's best cost depends on previously computed states.
Example 1
Input
n = 5 start = 0 moveCost(i, j) = 2 if j = i + 1 else 5
Output
[0, 2, 4, 6, 8]
Explanation
The cheapest way to reach each next position is to move one step at a time, costing 2 per move.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.