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.
My Java solution with o(n log n) time complexity and o(1) space complexity:
publicstaticintmaximumToys(List<Integer>prices,intk){// sort array ascendingCollections.sort(prices);// subtract price from k until k - price < 0intmaxToys=0;inti=0;while(k-prices.get(i)>=0){maxToys++;k-=prices.get(i);i++;}returnmaxToys;}
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 →
My Java solution with o(n log n) time complexity and o(1) space complexity: