Skip to content
LC-1833 Medium LeetCode

1833. Maximum Ice Cream Bars

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

class Solution(object):
    def maxIceCream(self, costs, coins):
        """
        :type costs: List[int]
        :type coins: int
        :rtype: int
        """
        costs.sort()
        for i, c in enumerate(costs):
            coins -= c
            if coins < 0:
                return i
        return len(costs)

Solution from kamyu104/LeetCode-Solutions · MIT