Mini-Max Sum

  • + 0 comments
    public static void miniMaxSum(List<Integer> arr) {
    // Write your code here
        long min =1000000000;
        long max =1;
        long tot =0;
    
        for(int i=0; i<arr.size(); i++) {
            long currValue = arr.get(i).longValue();
    
            if (currValue <= min) {
                min = currValue;
            }
            if (currValue >= max) {
                max = currValue;
            }
            tot = tot + currValue;
        }
        System.out.print("" +(tot-max) + " " +(tot-min));
    
    }