We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
publicstaticvoidminiMaxSum(List<Integer>arr){// Write your code hereintmin=Integer.MAX_VALUE;intmax=Integer.MIN_VALUE;longsum=0l;for(Integerval: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);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all 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.