Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 0 comments

    c#

    public static int maximumToys(List prices, int k)

    {
        prices.Sort();
        int spend = 0;
        int toys = 0;
        int i = 0;
        while (spend < k)
        {
            spend += prices[i];
            i++;
            toys++;            
        }
        toys--;
        return toys;
    }