You are viewing a single comment's thread. Return to all comments →
JAVA CODE public static void miniMaxSum(List arr) { long sumMax = 0; long max = Integer.MIN_VALUE; long min = Integer.MAX_VALUE; long sumMin = 0;
for(Integer i: arr) { if(i <= min){ min = i; } if (i >= max){ max = i; } } for(Integer j: arr){ if(min != j){ sumMax += j; } if(max != j){ sumMin += j; } if(min == max){ sumMax = sumMin = (min * (arr.size()-1)); } } System.out.println(sumMin + " " + sumMax); }
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 CODE public static void miniMaxSum(List arr) { long sumMax = 0; long max = Integer.MIN_VALUE; long min = Integer.MAX_VALUE; long sumMin = 0;