HackerRank Mini-Max Sum Probelm Solution C Solution
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(){ long long int a; long long int b; long long int c; long long int d; long long int e; long long int min, max; scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e); min = max = b + c + d + e; if (a + c + d + e < min) min = a + c + d + e; else if (a + c + d + e > max) max = a + c + d + e; if (a + b + d + e < min) min = a + b + d + e; else if (a + b + d + e > max) max = a + b + d + e; if (a + b + c + e < min) min = a + b + c + e; else if (a + b + c + e > max) max = a + b + c + e; if (a + b + c + d < min) min = a + b + c + d; else if (a + b + c + d > max) max = a + b + c + d; printf("%lld %lld", min, max); return 0; }
HackerRank Mini-Max Sum Probelm Solution in JavaScript
process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var a_temp = readLine().split(' '); var array = a_temp.map(Number).sort(function(a,b){return a-b}); var length = array.length; var ranges = []; ranges.push(array.slice(0,length -1)) ranges.push(array.slice(1,length)); var sums = ranges.map(function(range){ sum = range.reduce(function(sum, cur){return sum + cur}); return sum; }); console.log(sums.join(' ')); }
HackerRank Mini-Max Sum Probelm Solution Python
#!/bin/python import sys a,b,c,d,e = input().strip().split(' ') a,b,c,d,e = [int(a),int(b),int(c),int(d),int(e)] sums=[] sums.append(a+b+c+d) sums.append(a+b+c+e) sums.append(a+b+d+e) sums.append(b+c+d+e) sums.append(a+e+c+d) print(min(sums),max(sums))
0 Comments