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.
Approach :
1) Add all the elements of list
2) for finding minimum sum , subtract maximum element of list from sum
3) for finding maximum sum, subtract minimum element of list from sum
double sum=0;
for (int i = 0; i < arr.size(); i++) {
sum += arr.get(i);
}
double min = sum - Collections.max(arr);
double max = sum - Collections.min(arr);
System.out.printf("%.0f ", min);
System.out.printf("%.0f", max);
}
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
Approach : 1) Add all the elements of list 2) for finding minimum sum , subtract maximum element of list from sum 3) for finding maximum sum, subtract minimum element of list from sum