Skip to content

Practice Minimum Number of Coins for Fruits

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

Medium#2944
LeetCode Problem

Minimum Number of Coins for Fruits

Problem Statement

Fruits are numbered from 1 through prices.length. Buying fruit j costs prices[j - 1] coins and lets you take the next j fruits for free, limited by the end of the array. You may still buy a fruit that is already free to activate its own reward. Return the least total cost to acquire every fruit.

Source: Minimum Number of Coins for Fruits on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
prices = [3,1,2]
Output
4

# Example 2

Input
prices = [1,10,1,1]
Output
2

# Example 3

Input
prices = [26,18,6,12,49,7,45,45]
Output
39

Constraints

1 <= prices.length <= 1000
1 <= prices[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Minimum Number of Coins for Fruits.

Review your practice with PhantomCodeAI

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