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

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1509

class Solution:
    def minDifference(self, nums: List[int]) -> int:
        n = len(nums)
        if n < 5:
            return 0
        nums.sort()
        res = inf
        for l in range(4):
            r = 3 - l
            res = min(res, nums[n - 1 - r] - nums[l])
        return res