1509. Minimum Difference Between Largest and Smallest Value in Three Moves

class Solution:
    def minDifference(self, nums: List[int]) -> int:
        n = len(nums)
        if n <= 4:
            return 0

        nums.sort()
        ans = float('inf')
        for i in range(4):
            a = nums[i]
            b = nums[-4 + i]
            ans = min(ans, b - a)

        return ans