You are viewing a single comment's thread. Return to all comments →
Python 3 solutions with and without early exit:
def maxMin(k: int, arr: list[int]) -> int: arr.sort() offset = k - 1 min_unfairness = arr[offset] - arr[0] for i in range(k, len(arr)): if min_unfairness := min(arr[i] - arr[i - offset], min_unfairness): continue return 0 return min_unfairness def maxMin(k: int, arr: list[int]) -> int: k -= 1 arr.sort() return min(arr[i] - arr[i - k] for i in range(k, len(arr)))
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 →
Python 3 solutions with and without early exit: