Skip to content

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.

Easy#2144
LeetCode Problem

Minimum Cost of Buying Candies With Discount

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

Input
cost = [1,2,3]
Output
5

# Example 2

Input
cost = [6,5,7,9,2,2]
Output
23

# Example 3

Input
cost = [5,5]
Output
10

Constraints

1 <= cost.length <= 100
1 <= cost[i] <= 100

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.