| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
													Tags
													
											
												
												- join
 - Developer_JoyKim
 - MySQL
 - Programmers
 - SQL
 - JavaScript
 - select
 - 재귀함수
 - 역행자
 - 코딩공부
 - 알고리즘
 - 코드스테이츠
 - node.js
 - 코딩테스트
 - array.slice()
 - 개발자의 책장
 - 블록체인
 - 프로그래머스
 - Algorithms
 - 코플릿
 - 배열
 - for문
 - Hackerrank
 - Where
 - array.push()
 - 정규표현식
 - 자바스크립트
 - 개발자_조이킴
 - array
 - 최강의 인생
 
													Archives
													
											
												
												- Today
 
- Total
 
CodingSpace
[HackerRank/Algorithms] Warmup - Birthday Cake Candles 본문
			HackerRank/Algorithm
			
		[HackerRank/Algorithms] Warmup - Birthday Cake Candles
개발자_조이킴 2022. 8. 22. 22:35Problem. Warmup - Birthday Cake Candles
Link.
https://www.hackerrank.com/challenges/birthday-cake-candles/problem?isFullScreen=true
Plus Minus | HackerRank
Calculate the fraction of positive, negative and zero values in an array.
www.hackerrank.com
Description.
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.

Key Point.
My Answer.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});
function readLine() {
    return inputString[currentLine++];
}
/*
 * Complete the 'birthdayCakeCandles' function below.
 *
 * The function is expected to return an INTEGER.
 * The function accepts INTEGER_ARRAY candles as parameter.
 */
function birthdayCakeCandles(candles) {
    // find max value from array of candles
    let max = Math.max(...candles);
    
    // initialize count 0 for tallest of the candles
    let cnt = 0;
    
    for(let i = 0; i < candles.length; i++) {
        if(candles[i] === max)
            cnt++;
    }
    
    return cnt;
}
function main() {
    const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
    const candlesCount = parseInt(readLine().trim(), 10);
    const candles = readLine().replace(/\s+$/g, '').split(' ').map(candlesTemp => parseInt(candlesTemp, 10));
    const result = birthdayCakeCandles(candles);
    ws.write(result + '\n');
    ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
| [HackerRank/Algorithms] Warmup - Grading Students (0) | 2022.08.24 | 
|---|---|
| [HackerRank/Algorithms] Warmup - Time Conversion (0) | 2022.08.23 | 
| [HackerRank/Algorithms] Warmup - Mini-Max Sum (0) | 2022.08.22 | 
| [HackerRank/Algorithms] Warmup - Plus Minus (0) | 2022.08.21 | 
| [HackerRank/Algorithms] Warmup - Diagonal Difference (0) | 2022.08.21 | 
			  Comments