Created
June 16, 2017 16:59
-
-
Save mllopart/9305b6c5b61663ae95a71112ba4ab87d to your computer and use it in GitHub Desktop.
Birthday Cake Candles - Hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
''' | |
Colleen is turning n years old! Therefore, she has n candles of | |
various heights on her cake, and candle i has height . | |
Because the taller candles tower over the shorter ones, Colleen can only blow out the tallest candles. | |
Given the n for each individual candle, find and print the number of candles she can successfully blow out. | |
''' | |
import sys | |
def birthdayCakeCandles(n, ar): | |
#we sort the array descending, then it's matter | |
#to check the first number how many times is repeated | |
ar.sort(reverse=True) | |
firstNum = -1 | |
first = True | |
count = 0 | |
for a in ar: | |
if first == True: | |
firstNum = a | |
count +=1 | |
first = False | |
else: | |
if firstNum == a: | |
count+=1 | |
return count | |
n = int(input().strip()) | |
ar = list(map(int, input().strip().split(' '))) | |
result = birthdayCakeCandles(n, ar) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment