1833. Maximum Ice Cream Bars

To be truthful, I think that this problem’s difficulty should be easy instead of medium.

This solution aims to sort costs because the maximum number of popsicles is obtained with the least price.

func maxIceCream(costs []int, coins int) int {
	sort.Ints(costs)
	res := 0
	for _, cost := range costs {
		if coins - cost < 0 {
			break
		}
		res++
		coins -= cost
	}
	return res
}