Table of Contents

# Mini-Max Sum – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.

# Solutions of Algorithms Data Structures Hard HackerRank:

## Here are all the Solutions of Hard , Advanced , Expert Algorithms of Data Structure of Hacker Rank , Leave a comment for similar posts

# C++ Mini-Max Sum HackerRank Solution

#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 %lld\n", MN, MX); }

# Java Mini-Max Sum HackerRank Solution

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); } }

# Python 3 Mini-Max Sum HackerRank Solution

#!/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)

# JavaScript Mini-Max Sum HackerRank Solution

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); });

# C Mini-Max Sum HackerRank Solution

#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; }

## Leave a comment below