n as the length of the costs array.m as the maximum cost in the costs array.icecreams as 0, representing the number of ice creams bought.costsFrequency as an array of size m + 1, with all values set to 0.costs array, incrementing the corresponding index in costsFrequency for each cost.m.
a. While there are ice creams with the current cost and the boy has enough coins, buy an ice cream and reduce the coins accordingly.
b. Increment icecreams by the number of ice creams bought at the current cost.icecreams.