Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6a8fca8

Browse files
Add files via upload
1 parent 07d6e67 commit 6a8fca8

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

‎Birthday cake candles.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# You are in charge of the cake for your niece'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.
2+
3+
# For example, if your niece is turning years old, and the cake will have candles of height , , , , she will be able to blow out candles successfully, since the tallest candles are of height and there are such candles.
4+
5+
# Function Description
6+
7+
# Complete the function birthdayCakeCandles in the editor below. It must return an integer representing the number of candles she can blow out.
8+
9+
# birthdayCakeCandles has the following parameter(s):
10+
11+
# ar: an array of integers representing candle heights
12+
# Input Format
13+
14+
# The first line contains a single integer, , denoting the number of candles on the cake.
15+
# The second line contains space-separated integers, where each integer describes the height of candle .
16+
17+
# Constraints
18+
19+
# Output Format
20+
21+
# Return the number of candles that can be blown out on a new line.
22+
23+
# Sample Input 0
24+
25+
# 4
26+
# 3 2 1 3
27+
# Sample Output 0
28+
29+
# 2
30+
# Explanation 0
31+
32+
# We have one candle of height , one candle of height , and two candles of height . Your niece only blows out the tallest candles, meaning the candles where . Because there are such candles, we print on a new line.
33+
34+
35+
#!/bin/python3
36+
37+
import math
38+
import os
39+
import random
40+
import re
41+
import sys
42+
43+
# Complete the birthdayCakeCandles function below.
44+
def birthdayCakeCandles(ar):
45+
46+
counter = 0
47+
m = max(ar)
48+
49+
for i in range(0,len(ar)):
50+
if(ar[i] == m):
51+
counter += 1
52+
53+
return counter
54+
55+
56+
if __name__ == '__main__':
57+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
58+
59+
ar_count = int(input())
60+
61+
ar = list(map(int, input().rstrip().split()))
62+
63+
result = birthdayCakeCandles(ar)
64+
65+
fptr.write(str(result) + '\n')
66+
67+
fptr.close()
68+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /