Problem 2969 · Medium

Minimum Number of Coins for Fruits II

Buying a fruit makes the next few fruits free. Scan from the back with a monotone deque to find the cheapest total cost for every fruit.

Open the interactive visualisation