Birthday Cake Candles

Colleen is turning  n years old! Therefore, she has n  candles of various heights on her cake, and candle i has height height[i]. Because the taller candles tower over the shorter ones, Colleen can only blow out the tallest candles.

Given the  height for each individual candle, find and print the number of candles she can successfully blow out.

Input Format

The first line contains a single integer, n , denoting the number of candles on the cake.
The second line contains n space-separated integers, where each integer height[i] describes the height of the ith candle .

Output Format

Print the number of candles Colleen blows out on a new line.

Sample Input 0

4
3 2 1 3

Sample Output 0

2

 

Solution :

The problem is pretty easy. Since its given that only the biggest candle can be blown out, All you need total no of tallest candles and print that

Here is the code in Python 2.7

def birthdayCakeCandles(n, ar):
    h = {}
    for x in ar:
       if x in h:
           h[x] += 1
       else:
           h[x] = 1
    return h[max(ar)]
n = int(raw_input().strip())
ar = map(int, raw_input().strip().split(' '))
result = birthdayCakeCandles(n, ar)
print(result)

 

 

 

 

 

 

 

 

 

 

 

 

Leave a comment