In this HackerRank Mini-Max Sum problem solution you have 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.

Problem solution in JavaScript programming

function miniMaxSum(arr) {
  let min = 0;
  let max = 0;
  for(let element of arr.slice(0, arr.length-1))
    min += element;
  for(let element of arr.slice(1))
    max += element;
  console.log(`${min} ${max}`)

Problem solution in Python programming

def miniMaxSum(arr):
    max_val = 0
    min_val = 0
    for val in arr[:-1]:
        max_val = max_val + val
    for value in arr[1:]:
        min_val = min_val + value

Problem solution in C programming

void miniMaxSum(int arr_count, int* arr) {
    unsigned int min, max;
    long int sum;

    min = max = arr[0];
    sum = 0;
    for (int i = 0; i < arr_count; ++i) {

        if (arr[i] > max)    
            max = arr[i];
        if (arr[i] < min)
            min = arr[i];

        sum += arr[i];
    printf("%ld %ld\n",(sum - max), (sum - min));

Problem solution in Java programming

public static void miniMaxSum(List<Integer> arr) {
        long sum = 0L;
        int min = arr.get(0);
        int max = arr.get(0);
        for (Integer i : arr){
            sum += i;
            if(i > max){
                max = i;
            } else if(i < min) {
                min = i;
        System.out.print((sum - max)+" "+(sum - min));

The above are the easiest Hacker Rank Mini-Max Sum problem solutions ever on the internet. I hope you like them.

Categorized in: