I submitted my solution but it only work in 5/15 cases. I cant see errors or anything. Anyone has idea how to improve my code or why is it so bad overall?
class Result {
/*
* Complete the 'miniMaxSum' function below.
*
* The function accepts INTEGER_ARRAY arr as parameter.
*/
public static void miniMaxSum(List<Integer> arr) {
// Write your code here
Collections.sort(arr);
List<Integer> minArray = new ArrayList<>(arr);
List<Integer> maxArray = new ArrayList<>(arr);
int minSum = 0;
int maxSum = 0;
minArray.remove(minArray.size() - 1);
maxArray.remove(0);
for(int i = 0; i < minArray.size(); i++){
minSum = minSum + minArray.get(i);
}
for(int i = 0; i < maxArray.size(); i++){
maxSum = maxSum + maxArray.get(i);
}
System.out.println(minSum + " " + maxSum);
}
}
That's my result and link to the task is here if anyone wants to have a look: https://www.hackerrank.com/challenges/one-week-preparation-kit-mini-max-sum/problem?h_l=interview&isFullScreen=true&playlist_slugs[][]=preparation-kits&playlist_slugs[][]=one-week-preparation-kit&playlist_slugs[][]=one-week-day-one