Mark and Toys Discussions | Algorithms | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticintmaximumToys(List<int>prices,intk){intn=prices.Count;inttoyCount=0;inttotalSpent=0;prices.Sort();// Buy toys while the budget allowsfor(inti=0;i<n;i++){if(totalSpent+prices[i]<=k){totalSpent+=prices[i];toyCount++;}else{// If we can't afford this toy, stop the processbreak;}}}
Cookie support is required to access HackerRank
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 →
Using c#