#2944

Minimum Number of Coins for Fruits

specialist · 910 · lc medium +31 · 48.9% accepted · 317 likes · top 35%

Description

A 0-indexed array prices gives the coin cost of the (i+1)th fruit. Buying fruit (i+1) lets you claim any i of the next fruits at no cost. You may still purchase a free fruit to earn its free-fruit reward.

Return the minimum total coins needed to acquire every fruit.

Code

1
2
3