-
[HackerRank] Birthday Cake Candles c++Coding Test/HackerRank 2022. 7. 18. 11:34728x90
- Problem
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
candles = [4,4,1,3]
The maximum height candles are 4 units high. There are 2 of them, so return 2.
- Constraints
1<= n <= 10^5
1<= candles[i] <= 10^7
- Sample Input
4 3 2 1 3
- Sample Output
2
- Explanation
Candle heights are [3,2,1,3] . The tallest candles are 3 units, and there are 2 of them.
- Solutions
int birthdayCakeCandles(vector<int> candles) { sort(candles.begin(), candles.end(),greater<int>()); int n = candles.at(0); int cnt = 1; for(int i = 1; i < candles.size(); i++){ if(candles[i] == n) cnt++; } return cnt; }
728x90'Coding Test > HackerRank' 카테고리의 다른 글
[HackerRank] Compare the Triplets c++ (0) 2022.07.18 [HackerRank] Time Conversion c++ (0) 2022.07.18 [HackerRank] Mini-Max Sum c++ (0) 2022.07.16 [HackerRank] Staircase c++ (0) 2022.07.16 [HackerRank] Plus Minus c++ (0) 2022.07.16