Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Ice Cream Bars

XPChallenge Points: 20
levelLevel: Medium

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.

Example 1:

Input: costs = [2,1,2,1,3], coins = 6

Output: 4

Explanation:

He can buy bars costing 1,1,2,2 → total = 6.

Example 2:

Input: He can buy bars costing 1,1,2,2 → total = 6.

Output: 1

Explanation:

He can only afford the bar costing 2.

Example 3:

Input: costs = [4,4,4,4], coins = 10

Output: 2

Explanation:

He can buy any two bars costing 4 each.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result