Mini-Max Sum

Sort by

recency

|

269 Discussions

|

  • + 0 comments

    ![](wwwwwwhttps://heuk akun fire fire)

  • + 0 comments
    def miniMaxSum(arr):
        sortedarr = sorted(arr)
        print(sum(sortedarr[:4]), sum(sortedarr[1:]))
    
  • + 0 comments

    when I run this code it will pass correctly , during submition this code shows wrong ouput. But I run that input by custom input ( input should be the input what when i get wrong output) it shows correct output.

    !/bin/python3

    import math import os import random import re import sys

    #

    Complete the 'miniMaxSum' function below.

    #

    The function accepts INTEGER_ARRAY arr as parameter.

    #

    def miniMaxSum(arr): # Write your code here sum = 0 min = arr[0] max = 0 for i in arr: sum += i if i < min: min = i max = min else: min = min max = i min_value = sum - max max_value = sum - min print(min_value ,end=' ') print(max_value)

    if name == 'main':

    arr = list(map(int, input().rstrip().split()))
    
    miniMaxSum(arr)
    
  • + 0 comments

    function miniMaxSum(arr) { let sum=0 let min =arr[0]; let max =arr[0]; for(let i= 0; i max){ max= arr[i] } } for(let i=0; i{sum - min})

    }

  • + 1 comment

    Java 15

    public static void miniMaxSum(List<Integer> arr) {
    // Write your code here
    int min = arr.get(0) , max = arr.get(0) ;
    int sum = 0;
    for(int i = 0 ; i < arr.size(); i++){
        if(arr.get(i) > max){
            max = arr.get(i);
        }
        if (arr.get(i) < min ){
            min = arr.get(i);
        }
        sum+= arr.get(i);
    }
    System.out.printf("%d %d",sum-max,sum-min);
    }
    

    }