You are viewing a single comment's thread. Return to all comments →
javascript solution:
function maximumToys(prices, k) { let total = 0; let toys = []; let sortedPrices = prices.sort((a, b) => a - b); for (let p of sortedPrices) { if (total + p <= k) { toys.push(p); total += p; } else { return toys.length; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Mark and Toys
You are viewing a single comment's thread. Return to all comments →
javascript solution: