Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 0 comments

    Straigthforward python solution:

    def maximumToys(prices, k):

    sorted_prices = sorted(prices)
    cost = 0    
    
    for i in range(len(prices)):
        cost += sorted_prices[i]
        if cost > k:
            return i