2144. Minimum Cost of Buying Candies With Discount
Easy
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.
For example, if there are
4
candies with costs1
,2
,3
, and4
, and the customer buys candies with costs2
and3
, they can take the candy with cost1
for free, but not the candy with cost4
.
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.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= cost.length <= 100
1 <= cost[i] <= 100
解題
Previous2133. Check if Every Row and Column Contains All NumbersNext2180. Count Integers With Even Digit Sum
Last updated