Skip to content

Practice Minimum Cost to Reach Every Position

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

Easy#3502
LeetCode Problem

Minimum Cost to Reach Every Position

Problem Statement

You start at position n in a line of people at positions 0 through n. Swapping with person i in front of you costs cost[i]; swapping with a person behind you is free. Return an array whose entry i is the minimum total cost required to reach position i.

Source: Minimum Cost to Reach Every Position on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
cost = [5,3,4,1,3,2]
Output
[5,3,3,1,1,1]

# Example 2

Input
cost = [1,2,4,6,7]
Output
[1,1,1,1,1]

Constraints

1 <= n == cost.length <= 100
1 <= cost[i] <= 100

Related LeetCode Problems

Practice more problems similar to Minimum Cost to Reach Every Position.

Review your practice with PhantomCodeAI

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