Skip to content

Latest commit

 

History

History

1833-MaximumIceCreamBars

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Maximum Ice Cream Bars

Problem can be found in here!

Solution: Sorting + Greedy

def maxIceCream(costs: List[int], coins: int) -> int:
    index = 0
    costs.sort()

    while coins >= 0 and index < len(costs):
        if costs[index] <= coins:
            coins -= costs[index]
            index += 1
        else:
            break

    return index

Time Complexity: O(nlogn), Space Complexity: O(n)