2091. Removing Minimum and Maximum From Array
class Solution:
def minimumDeletions(self, nums: List[int]) -> int:
max_value, min_value = float("-inf"), float('inf')
max_value_index, min_value_index = 0, 0
N = len(nums)
for i, v in enumerate(nums):
if v > max_value:
max_value = v
max_value_index = i
if v < min_value:
min_value = v
min_value_index = i
bigger_index = max(max_value_index, min_value_index)
smaller_index = min(max_value_index, min_value_index)
return min(bigger_index + 1, # case 1
N - bigger_index + smaller_index + 1, # case 2
N - smaller_index) # case 3