You are viewing a single comment's thread. Return to all comments →
Solution in Java (more optimised version available in the comments):
public static void miniMaxSum(List arr) { Long sumOfAll = arr.stream().mapToLong(i->i).sum(); List minMaxSumList = new ArrayList(); for(int i=0; i<=arr.size() - 1; i++) { minMaxSumList.add(sumOfAll - arr.get(i)); } Collections.sort(minMaxSumList); System.out.println(minMaxSumList.get(0)+" "+minMaxSumList.get(minMaxSumList.size()-1)); //Input: 769082435 210437958 673982045 375809214 380564127 //Output: 1640793344 2199437821 }
}
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 →
Solution in Java (more optimised version available in the comments):
public static void miniMaxSum(List arr) { Long sumOfAll = arr.stream().mapToLong(i->i).sum();
List minMaxSumList = new ArrayList(); for(int i=0; i<=arr.size() - 1; i++) { minMaxSumList.add(sumOfAll - arr.get(i)); } Collections.sort(minMaxSumList); System.out.println(minMaxSumList.get(0)+" "+minMaxSumList.get(minMaxSumList.size()-1)); //Input: 769082435 210437958 673982045 375809214 380564127 //Output: 1640793344 2199437821 }
}