Birthday Cakes

Find the count of tallest candle that can be blown out

You are in charge of the cake for your daughter's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she'll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out.

For example, if your daughter is turning 4 years old, and the cake will have 4 candles of height 4, 4, 1, 3, she will be able to blow out 2 candles successfully, since the tallest candles are of height and there are such candles.

Input: An array containing height of candle [4,4,1,3]

Output: Print the number of candles that can be blown out. 2

Explanation: We have one candle of height 1, one candle of height 2, and two candles of height 3. Your daughter only blows out the tallest candles, meaning the candles where height=3. Because there are 2 such candles, we print 2.

Solution: We reverse sort an array so that we get to tallest first in an array. Now we compare the tallest to other elements ie. first element to other element. If other elements has same value its count gets increment and final value will be the total number of tallest element.

for($i=0;$i<$len;$i++) {
	if($arr[0]==$currElement) {
echo $cnt;

We need your support to operate it properly. We have lots of ideas but less fund, so help us with your funding.


Thoughts of the day

A perfection of means, and confusion of aims, seems to be our main problem

Albert Einstein
Sell your product online

Do you want to sell products online with no extra cost?

Send your details, our executive will contact you




Tutorial On Request
Q. Ask us for any tutorial or any thing which helps to build your career better.