Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

HackerRank Mini Max Sum problem solution

YASH PAL, 31 July 20243 May 2025

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

Example

arr = [1,3,5,7,9]

The minimum sum is 1+3+5+7 = 16 and the maximum sum is 3+5+7+9 = 24. The function prints

16 24

Function Description

Complete the miniMaxSum function in the editor below.

miniMaxSum has the following parameter(s):

arr: an array of  integers

Print

Print two space-separated integers on one line: the minimum sum and the maximum sum of  of  elements.

Input Format

A single line of five space-separated integers.

Constraints

1 <= arr[i] <= 10^9

Output Format

Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)

Hackerrank mini max sum solution
Hackerrank mini max sum solution

HackerRank Mini max sum problem solution in Python.

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the miniMaxSum function below.
def miniMaxSum(arr):
    arr.sort()
    hold = [None]*int(len(arr)-3)
    for i in range(0,len(arr)-3):
        temp = 0
        for j in range(i,i+4):
            temp = temp + arr[j]
        hold[i] = temp
    
    print(hold[0],hold[-1])


if __name__ == '__main__':
    arr = list(map(int, input().rstrip().split()))

    miniMaxSum(arr)

Problem solution in Java Programming.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        long[] m=new long[5];
        for(int i=0;i<5;i++){
            m[i]=in.nextLong();
        }
        Arrays.sort(m);
        long x=0;
        long y=0;
        for(int i=0;i<4;i++){
            x+=m[i];
        }
        for(int i=1;i<5;i++){
            y+=m[i];
        }
        System.out.println(x+" "+y);
    }
}

 

Problem solution in C++ programming.

#include <algorithm>
#include <string.h>
#include <vector>
#include <cstdio>
#include <climits>
#include <iostream>
using namespace std;
typedef long long lld;

lld arr[6], N = 5;

int main ()
{
    //freopen("input.txt", "r", stdin);

    lld allsum = 0;
    lld MN = LLONG_MAX, MX = LLONG_MIN;

    for (int i=1; i<=N; i++)
    {
        scanf("%lld", &arr[i]);
        allsum += arr[i];
    }

    for (int i=1; i<=N; i++)
    {
        lld cur = allsum - arr[i];
        MN = min(MN, cur);
        MX = max(MX, cur);
    }

    printf("%lld %lldn", MN, MX);
}

 

 

Problem solution in C programming.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    
    int a[5];
    long sum=0;
    for(int i=0;i<5;i++){
        scanf("%d",a+i);
        sum+=a[i];
    }
    int min=a[0];
    int max=a[0];
    for(int i=1;i<5;i++){
        if(a[i]>max)
            max=a[i];
        if(a[i]<min)
            min=a[i];
    }
    printf("%ld %ld",sum-max,sum-min);
    return 0;
}

 

Problem solution in JavaScript programming.

function processData(input) {
    var v = input.split(' ');
    for (var i = 0; i < v.length; i++) {
        v[i] = parseInt(v[i])
    }
    var max = -Infinity;
    var min = Infinity;
    for (var i = 0; i < v.length; i++) {
        var sum = 0;
        for (var j = 0; j < v.length; j++) {
            if ( i != j ) {
                sum += v[j];
            }
        }
        if (sum < min) min = sum;
        if (sum > max) max = sum;
    }
    console.log(min, max)
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Other problems solutions

  • HackerRank Birthday cake candles problem solution
  • HackerRank Time conversion problem solution
  • HackerRank Grading students problem solution
  • HackerRank Apple and orange problem solution
  • HackerRank Number Line Jumps problem solution
Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes