Challenge Solution Sort the prices and add them until the sum doesn’t exceed k. (defn maximum-toys [prices k] "TOC: <5m Complexity: O(n log n), (= n (count prices))" (loop [prices (sort prices) spent 0 toys 0] (if-not (> (+ spent (first prices)) k) (recur (rest prices) (+ spent (first prices)) (inc toys)) toys))) (maximum-toys [1 12 5 111 200 1000 10] 50)
Hackerrank Maximum Toys
Hackerrank Maximum Toys
Hackerrank Maximum Toys
Challenge Solution Sort the prices and add them until the sum doesn’t exceed k. (defn maximum-toys [prices k] "TOC: <5m Complexity: O(n log n), (= n (count prices))" (loop [prices (sort prices) spent 0 toys 0] (if-not (> (+ spent (first prices)) k) (recur (rest prices) (+ spent (first prices)) (inc toys)) toys))) (maximum-toys [1 12 5 111 200 1000 10] 50)