Mark and Toys Discussions | Algorithms | HackerRank

Mark and Toys

  • + 0 comments

    Java Solution

    public static int maximumToys(List prices, int k) { // Write your code here Collections.sort(prices); int toys=0; /for(int i=0;i/

        int i=0;
        while(prices.get(i)<k && i<prices.size()){
            k=k-prices.get(i);
            toys=toys+1;
            i++;
        }
        return toys;
    
    }