Skip to content
LC-2144 Easy LeetCode

2144. Minimum Cost of Buying Candies With Discount

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 62% Topics: Array, Greedy, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(1)

# greedy
class Solution(object):
    def minimumCost(self, cost):
        """
        :type cost: List[int]
        :rtype: int
        """
        cost.sort(reverse=True)
        return sum(x for i, x in enumerate(cost) if i%3 != 2)

Solution from kamyu104/LeetCode-Solutions · MIT