Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 0 comments

    Here is my c++ solution, you also have a vidéo explanation here : https://youtu.be/DFQO52aB-qI

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