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.
/*
* Complete the 'miniMaxSum' function below.
* The function accepts INTEGER_ARRAY arr as parameter.
*/
public static void miniMaxSum(List<Integer> arr) {
long totalSum = 0;
long min = Long.MAX_VALUE;
long max = Long.MIN_VALUE;
for (int num : arr) {
totalSum += num;
if (num < min) min = num;
if (num > max) max = num;
}
long minSum = totalSum - max; // exclude largest
long maxSum = totalSum - min; // exclude smallest
System.out.println(minSum + " " + maxSum);
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] input = bufferedReader.readLine().trim().split(" ");
List<Integer> arr = new ArrayList<>();
for (int i = 0; i < 5; i++) {
arr.add(Integer.parseInt(input[i]));
}
Result.miniMaxSum(arr);
bufferedReader.close();
}
}
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 →
import java.io.; import java.util.;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}