You are viewing a single comment's thread. Return to all comments →
long maxval =0; long minval =0; Collections.sort(arr);
for(int i =0 ; i <= 2 ; i ++){ minval += Math.addExact(arr.get(i), arr.get(i + 1)); i++; } for(int i = arr.size() - 1 ; i >= 2 ; i -- ){ maxval += Math.addExact(arr.get(i), arr.get(i - 1)); i--; } System.out.println(minval + " " + maxval);
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 →
long maxval =0; long minval =0; Collections.sort(arr);