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.
- Prepare
- Algorithms
- Warmup
- Mini-Max Sum
- Discussions
Mini-Max Sum
Mini-Max Sum
Sort by
recency
|
5894 Discussions
|
Please Login in order to post a comment
java 8 solution
public static void miniMaxSum(List arr) { // Write your code here Collections.sort(arr); long min=0; long max=0; for(int i=0;i<(arr.size()-1);i++){ min+=arr.get(i); } for(int i=1;i
Js
}
Here is my c++ solution, you can watch the explanation here : https://youtu.be/2GlHrf4HQPE
In python we can do it in a single line:
Can anyone tell me why my code was wrong and why below code not able to pass all test case but few.
Collections.sort(arr); Integer min=arr.get(0); Integer max=arr.get(arr.size()-1); Integer minSum=0; Integer maxSum=0; for (Integer i:arr) { if(i!=max) minSum+=i; if(i!=min) maxSum+=i; 34
System.out.println(minSum+" "
+maxSum );