Maximum Ice Cream Bars
MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.A shop sells n ice cream bars; bar i costs costs[i] coins. You have coins coins and may buy the bars in any order. Return the most bars you can buy.
costs = [1, 3, 2, 4, 1], coins = 7 → 4 (1 + 1 + 2 + 3)
costs = [10, 6, 8, 7, 7, 8], coins = 5 → 0
costs = [1, 6, 3, 1, 2, 5], coins = 20 → 6Constraints
costs.length == n1 <= n <= 10^51 <= costs[i] <= 10^51 <= coins <= 10^8