Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created January 2, 2019 12:49
Show Gist options
  • Select an option

  • Save kharioki/263be25c44a73f9dddcb54c49e4ed189 to your computer and use it in GitHub Desktop.

Select an option

Save kharioki/263be25c44a73f9dddcb54c49e4ed189 to your computer and use it in GitHub Desktop.
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.replace(/\s*$/, '')
.split('\n')
.map(str => str.replace(/\s*$/, ''));
main();
});
function readLine() {
return inputString[currentLine++];
}
// Complete the miniMaxSum function below.
function miniMaxSum(arr) {
arr.sort((a, b) => a - b)
let first = arr.slice(0, -1);
let last = arr.slice(1)
let minSum = first.reduce((a, b) => a + b, 0);
let maxSum = last.reduce((a, b) => a + b, 0);
console.log(minSum + " " + maxSum)
}
function main() {
const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));
miniMaxSum(arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment