Mini-Max Sum HackerRank Algorithms
TIME O(NLOGN)
SPACE O(1)
public static void miniMaxSum(List<Integer> arr) {
Collections.sort(arr);
long sum2=0;
sum2=Long.valueOf(arr.get(0))+Long.valueOf(arr.get(1))+Long.valueOf(arr.get(2))+Long.valueOf(arr.get(3));
System.out.print(sum2+" ");
long sum1=0;
sum1=Long.valueOf(arr.get(4))+Long.valueOf(arr.get(1))+Long.valueOf(arr.get(2))+Long.valueOf(arr.get(3));
System.out.println(sum1);
// Write your code here
}
}
Thanks for Reading.
Comments
Post a Comment