| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 프로그래머스
- 배열
- select
- node.js
- 개발자_조이킴
- 자바스크립트
- 코딩공부
- 알고리즘
- Hackerrank
- join
- 정규표현식
- SQL
- 역행자
- Where
- 개발자의 책장
- 코딩테스트
- Programmers
- Algorithms
- JavaScript
- array.slice()
- 재귀함수
- for문
- array
- Developer_JoyKim
- 코드스테이츠
- 코플릿
- 블록체인
- MySQL
- 최강의 인생
- array.push()
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Warmup - Mini-Max Sum 본문
Problem. Warmup - Mini-Max Sum
Link.
https://www.hackerrank.com/challenges/mini-max-sum/problem?isFullScreen=true
Mini-Max Sum | HackerRank
Find the maximum and minimum values obtained by summing four of five integers.
www.hackerrank.com
Description.
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Key Point.
My Answer.
'use strict';
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 'miniMaxSum' function below.
*
* The function accepts INTEGER_ARRAY arr as parameter.
*/
function miniMaxSum(arr) {
// Write your code here
arr.sort();
let min = 0;
let max = 0;
for(let i = 0; i < arr.length; i++) {
if(i !== arr.length - 1)
min = min + arr[i];
if(i !== 0)
max = max + arr[i];
}
console.log(min, max);
}
function main() {
const arr = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
miniMaxSum(arr);
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
| [HackerRank/Algorithms] Warmup - Time Conversion (0) | 2022.08.23 |
|---|---|
| [HackerRank/Algorithms] Warmup - Birthday Cake Candles (0) | 2022.08.22 |
| [HackerRank/Algorithms] Warmup - Plus Minus (0) | 2022.08.21 |
| [HackerRank/Algorithms] Warmup - Diagonal Difference (0) | 2022.08.21 |
| [HackerRank/Algorithms] Warmup - A Very Big Sum (0) | 2022.08.19 |
Comments