Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

Minimum Number of Coins for Fruits (medium)

Problem Statement

You are given an array of integers prices where each element prices[i] represents the number of coins required to buy the i<sup>th</sup> fruit.

The fruit market has the following reward for each fruit:

  • If you buy the i<sup>th</sup> fruit for prices[i] coins, you can get the next (i + 1) fruits for free.

Note: Even if you have the option to take certain fruits for free, you can still choose to purchase them at their respective prices[j] to gain the reward for the next fruits.

Return the minimum number of coins needed to get all the fruits.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content