You are viewing a single comment's thread. Return to all comments →
Java
public static int maxMin(int k, List<Integer> arr) { int currentUnfairness = 0; int minUnfairness = Integer.MAX_VALUE; List <Integer> sortedArr = arr.stream().sorted().collect(Collectors.toList()); for (int i = 0, j = k - 1; j < sortedArr.size(); i++, j++) { currentUnfairness = sortedArr.get(j) - sortedArr.get(i); minUnfairness = Math.min(minUnfairness, currentUnfairness); } return minUnfairness; }
Seems like cookies are disabled on this browser, please enable them to open this website
Max Min
You are viewing a single comment's thread. Return to all comments →
Java