Skip to content

Instantly share code, notes, and snippets.

@JonathanLalou
Created June 27, 2021 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanLalou/3b20c33e0c2ed143d09dddefe59c0004 to your computer and use it in GitHub Desktop.
Save JonathanLalou/3b20c33e0c2ed143d09dddefe59c0004 to your computer and use it in GitHub Desktop.
public static int maxMin(int k, List<Integer> arr) {
// Write your code here
if (k == 1) return 0;
Collections.sort(arr);
int unfairness = Integer.MAX_VALUE;
int size = arr.size();
for (int i = 0; i <= size - k; i++) {
unfairness = Math.min(unfairness, arr.get(i + k - 1) - arr.get(i));
}
return unfairness;
}
@JonathanLalou
Copy link
Author

15' (5' for the first version, 10' to fix the test#16 !!!!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment