• + 0 comments

    Java Solution. Sum the whole array values and at the same time get the min and max values from the array. At the end just substract the min and max values from the sum.

        public static void miniMaxSum(List<Integer> arr) {
        // Write your code here
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            long sum = 0l;
            
            for(Integer val : arr){
                sum += val;
                min = Math.min(min,val);
                max = Math.max(max,val);
            }
            
            System.out.print(sum-max);
            System.out.print(" ");
            System.out.print(sum-min);
    
        }