It's a scorching hot summer day, and a young boy walks into an ice cream shop with his hard-earned coins jingling in his pocket. ๐ฆ
The shop displays n different ice cream bars, each with its own price tag. You're given an array costs where costs[i] represents the price of the i-th ice cream bar in coins.
The boy has exactly coins coins to spend and wants to maximize his happiness by buying as many ice cream bars as possible. Since he's smart about spending, he can choose to buy the ice cream bars in any order that gives him the best deal.
Your task: Return the maximum number of ice cream bars the boy can buy with his available coins.
Special Requirement: You must solve this problem using counting sort for optimal performance.
Input & Output
Constraints
-
costs.length == n -
1 โค n โค 105 -
1 โค costs[i] โค 105 -
1 โค coins โค 108 - Must use counting sort for optimal solution