You are viewing a single comment's thread. Return to all comments →
Java, O(n log n)
Collections.sort(arr); int minUnfairness = Integer.MAX_VALUE; for (int i = 0; i <= arr.size() - k; i++) { int unfairness = arr.get(i + k - 1) - arr.get(i); if (unfairness < minUnfairness) { minUnfairness = unfairness; } } 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, O(n log n)