Mini-Max Sum

Sort by

recency

|

946 Discussions

|

  • + 0 comments

    def miniMaxSum(arr): total_sum = sum(arr) min_val = min(arr) max_val = max(arr) min_sum = total_sum - max_val max_sum = total_sum - min_val print(min_sum, max_sum)

    if name == 'main':

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

    java

    public static void miniMaxSum(List arr) { // Write your code here long sum = 0 ; for(int i=0; i< arr.size(); i++) { sum = sum + arr.get(i) ; } long max = 0; long min= sum; long current; for(int i=0; i< arr.size(); i++) { current = sum - arr.get(i) ; if(max < current) { max = current; } if(current < min) { min = current; }

    }
     System.out.println(min+ " "+ max);
    
    }
    
  • + 0 comments

    so simple in py

    def sumMethod(idx,arr):
        sum = 0
        for idxs in range(len(arr)):
            if idxs ==idx:
                continue
            record = arr[idxs]
            sum+=record
        return sum
    
    def miniMaxSum(arr):
        # Write your code here
        res = []
        for idx in range(len(arr)):
            sumRecord = sumMethod(idx,arr)
            res.append(sumRecord)
        res.sort()
        max = res[len(res)-1]
        min = res[0]
        print(min,max)
        return         
    
  • + 0 comments

    python - why is this failing test 4?

    total = sum(arr)
    min = total
    max = 0
    
    for x in arr:
    		if (total - x) > max:
    				max = total - x
    		elif (total - x) < min:
    				min = total - x
    
    print(f"{min} {max}")
    

    why is this failing test 4? undefined

  • + 0 comments

    in C

    void miniMaxSum(int arr_count, int* arr){
        
        /* long int because the output more than 32 bit so we will deal with (long int) 64 bit*/
        
        long int maxN=arr[0],     /* max number in array*/
         minN=arr[0],             /* min number in array*/
          sum=0;                  /* the sum of all elements */
        
        for(int i=0;i<arr_count;i++){
            if(maxN < arr[i]) maxN = arr[i]; /* max number in array */
            if(minN > arr[i]) minN = arr[i]; /* min number in array */
            sum+=arr[i];                     /* summing */
        }
     
         /* the lowest value is sum-maxValue, the highest value is sum-minValue*/   
        printf("%ld %ld\n",sum-maxN, sum-minN);
    }