Mini-Max Sum

Sort by

recency

|

398 Discussions

|

  • + 0 comments

    import java.util.*;

    public class Main { public static void main(String[] args) { List arr = new ArrayList<>(Arrays.asList(256741038,623958417,467905213,714532089,938071625));

      long totalSum = arr.stream().mapToLong(Integer::longValue).sum();
      System.out.println(totalSum);
      long max = 0;
      long min = totalSum;
      for (int value : arr){
        long temp = totalSum - value;
        if (temp > max) max = temp;
        if (temp < min) min = temp;
      }
    
      System.out.print(min+" "+max);
    

    } }

  • + 0 comments

    public static void miniMaxSum(List arr) { // Write your code here int sum = 0; int max = 0; int min = 0; for(int i=0;i

  • + 0 comments

    public static void miniMaxSum(List arr) { // Write your code here int sum = 0; int max = 0; int min = 0; for(int i=0;i

  • + 0 comments
    def miniMaxSum(arr):
        # Write your code here
        arr.sort()
        
        min_sum=sum(arr[0:len(arr)-1])
        max_sum=sum(arr[1:len(arr)])
        
        print(min_sum,max_sum)
    
  • + 0 comments
            long total = 0 ;
            long min = arr.get(0);
            long max = arr.get(0);
            for(int i: arr)
            {
                total += i ;
                if(i < min)
                {
                    min = i ;
                } 
                
                if(i > max)
                {
                    max = i ;
                }
            }
            
            long minSum = total - max;
            long maxSum = total - min;
            System.out.print(minSum + " " + maxSum);