2248. Minimum Cost of Buying Candies With Discount
My accepted Python solution to LeetCode problem 2248, Minimum Cost of Buying Candies With Discount, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.3MB, accepted 2026-01-01.
class Solution:
def minimumCost(self, cost: List[int]) -> int:
cost.sort(reverse=True)
total = 0
for i in range(len(cost)):
if (i + 1) % 3 != 0:
total += cost[i]
return total