LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.3MB, accepted 2026-01-01.

python
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

Source