#3502

Minimum Cost to Reach Every Position

newbie · 180 · lc easy +15 · 83.3% accepted · 66 likes · top 95%

Description

You start at position n in a queue of n + 1 people (positions 0 through n). Moving forward requires paying cost[i] to swap with person at position i; people behind you may swap past you for free.

Return array answer of size n, where answer[i] is the minimum cost to reach position i.

Code

1
2
3