Problem statement

https://binarysearch.com/problems/Minimize-Amplitude-After-K-Removals/

Solution

Sort numbers and look at window of size n - k.

Complexity

It is O(n log n) for time and O(n) for space.

Code

class Solution:
    def solve(self, A, k):
        A, n = sorted(A), len(A)
        return min(A[i+n-k-1] - A[i] for i in range(k+1))