Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 2 comments

    C++ solution :

    int maximumToys(vector<int> prices, int k) {
        sort(prices.begin(), prices.end());
        int i=0;
        while(k>0)
            k-=prices[i++];
        return i-1;
    }