You are viewing a single comment's thread. Return to all comments →
Java:
public static int maxMin(int k, List arr) {
int[] arr2 = arr.stream().mapToInt(i -> i).toArray(); //primitive arrays are faster Arrays.sort(arr2); int diff = Integer.MAX_VALUE; for (int j=0; j < arr2.length - k + 1; ++j) { if (arr2[j+k-1] - arr2[j] < diff) { diff = arr2[j+k-1] - arr2[j]; } } return diff; }
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: