728x90
반응형
SMALL
You are in charge of the cake for a child's birthday. It will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Your task is to count how many candles are the tallest.
Example
The tallest candles are 4 units high. There are 2 candles with this height, so the function should return 2.
Function Description
Complete the function with the following parameter(s):
- : the candle heights
Returns
- : 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.
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'birthdayCakeCandles' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY candles as parameter.
*/
public static int birthdayCakeCandles(List<Integer> candles) {
// Write your code here
int max = Collections.max(candles);
int dap = 0;
for(Integer i : candles){
if (max == i){
dap++;
}
}
return dap;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int candlesCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> candles = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());
int result = Result.birthdayCakeCandles(candles);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}

728x90
반응형
LIST
'알고리즘 단련장 > 해커랭크' 카테고리의 다른 글
[해커랭크] Fun Game (0) | 2025.08.07 |
---|---|
[해커랭크] Time Conversion (0) | 2025.08.06 |
[해커랭크] Mini-Max Sum (0) | 2025.08.06 |
[해커랭크] Staircase (1) | 2025.07.27 |
[해커랭크] Plus Minus (1) | 2025.07.27 |