-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.java
39 lines (33 loc) · 1.02 KB
/
Solution.java
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
//Problem: https://www.hackerrank.com/challenges/birthday-cake-candles
//Java 8
/*
Initial Thoughts:
We can keep a running max and update it if we
find something larger, if we find something smaller
we just keep looking and if we find something equal
then we increment a counter variable
Time Complexity: O(n) //We must check the height of every candle
Space Complexity: O(1) //We only store a max and a frequency
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int tallest = 0;
int frequency = 0;
for(int i=0; i < n; i++){
int height = in.nextInt();
if(height > tallest){
tallest = height;
frequency = 1;
}
else if(height == tallest) frequency++;
}
System.out.println(frequency);
}
}