Practice Minimum Cost of Buying Candies With Discount
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free. The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought. Given a 0-indexed integer array cost, where cost[i] denotes the cost of the ith candy, return the minimum cost of buying all the candies.
Source: Minimum Cost of Buying Candies With Discount on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
cost = [1,2,3]
5
# Example 2
cost = [6,5,7,9,2,2]
23
# Example 3
cost = [5,5]
10
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Cost of Buying Candies With Discount.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.