Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 0 comments
    function maximumToys(prices, k) {
        const sortedPrices = prices.sort((a, b)=> a-b)
        let total = 0
        let count =0
        while((total + sortedPrices[count]) < k){
            total +=sortedPrices[count]
            count++
        }
        return count
    }