-
Notifications
You must be signed in to change notification settings - Fork 3
/
BirthdayCakeCandles.java
39 lines (32 loc) · 1.03 KB
/
BirthdayCakeCandles.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
// https://www.hackerrank.com/challenges/birthday-cake-candles/problem
package warmup;
import java.util.Arrays;
import java.util.Scanner;
public class BirthdayCakeCandles {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int length = scanner.nextInt();
int[] array = getArray(length);
System.out.println(blownCandles(array));
}
private static int[] getArray(int length) {
int[] array = new int[length];
for (int index = 0 ; index < array.length ; index++) {
array[index] = scanner.nextInt();
}
return array;
}
private static int blownCandles(int[] array) {
int maximum = Arrays.stream(array).max().getAsInt();
return frequency(array, maximum);
}
private static int frequency(int[] array, int element) {
int count = 0;
for (int number : array) {
if (number == element) {
count++;
}
}
return count;
}
}