Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 433 Bytes

mark-and-toys.MD

File metadata and controls

21 lines (19 loc) · 433 Bytes

Mark and Toys (HackerRank)

https://www.hackerrank.com/challenges/mark-and-toys


// Complete the maximumToys function below.
int maximumToys(vector<int> prices, int k) {
    std::sort(prices.begin(), prices.end());
    int toy_count = 0;
    for(double price: prices) {
        k -= price;
        if (k >= 0) {
            ++toy_count;
        } else {
            break;
        }
    }
    return toy_count;
}