Mean of Array After Removing Some Elements LeetCode solution in Java
1class Solution {2public double trimMean(int[] arr) {3Arrays.sort(arr);4int length = arr.length;5int toRemove = length * 5 / 100;6int total = 0;7for (int number : arr) {8total += number;9}10for (int i = 0; i < toRemove; i++) total -= arr[i];11for (int i = length - 1; i >= length - toRemove; i--) total -= arr[i];12length -= (2 * toRemove);13return (double) ((double) total / (double) length);14}15}