You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we remove any number not touching the sides (e.g. 8), the max interval can only increase (4->8 will become 4->9), because the new difference between the hole made by removing the number will add together. So the strategy to minimize difference is removing numbers from the edges. We can use dp for this, as shown above.
"""
from functools import lru_cache
class Solution:
def solve(self, nums, k):
diffs=[nums[i]-nums[i-1] for i in range(1,len(nums))]