2944. Minimum Number of Coins for Fruits
You are at a fruit market with different types of exotic fruits on display.
You are given a 1-indexed array
prices
, whereprices[i]
denotes the number of coins needed to purchase theith
fruit.The fruit market has the following offer:
- If you purchase the
ith
fruit atprices[i]
coins, you can get the nexti
fruits for free.Note that even if you can take fruit
j
for free, you can still purchase it forprices[j]
coins to receive a new offer.Return the minimum number of coins needed to acquire all the fruits.
1 | class Solution { |