A boy wants to buy ice cream bars on a very hot day.
He has coins amount of money, and there are n ice cream bars available.
The price of each bar is given in the array costs, where costs[i] is the cost of the i-th bar.
He may buy the bars in any order, and the goal is to maximize the total number of bars he can purchase using his limited coins.
You are required to solve this problem using counting sort to manage the costs efficiently.
Return the maximum number of ice cream bars he can buy.
Input: costs = [2,1,2,1,3], coins = 6
Output: 4
Explanation:
He can buy bars costing 1,1,2,2 → total = 6.
Input: He can buy bars costing 1,1,2,2 → total = 6.
Output: 1
Explanation:
He can only afford the bar costing 2.
Input: costs = [4,4,4,4], coins = 10
Output: 2
Explanation:
He can buy any two bars costing 4 each.
Accepted:
Submission: