-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCandleCakes.rb
More file actions
61 lines (43 loc) · 1.2 KB
/
Copy pathCandleCakes.rb
File metadata and controls
61 lines (43 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
=begin
Birthday Cake Candles
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.
Example
The maximum height candles are units high. There are of them, so return .
Function Description
Complete the function birthdayCakeCandles in the editor below.
birthdayCakeCandles has the following parameter(s):
int candles[n]: the candle heights
Returns
int: the number of candles that are tallest
Input Format
The first line contains a single integer, , the size of .
The second line contains space-separated integers, where each integer describes the height of .
Constraints
Sample Input 0
4
3 2 1 3
Sample Output 0
2
Explanation 0
Candle heights are . The tallest candles are units, and there are of them.
=end
input = [0, 0, 0, 0, 1]
def blown_candles(input)
frequency = 1
maxNumber = 0
begin
input.each do |x|
if(maxNumber.eql? x)
frequency += 1
elsif(maxNumber <= x)
maxNumber = x
frequency = 1
end
end
rescue
p "came something wrong"
ensure
return frequency
end
end
p blown_candles(input)