2091. Removing Minimum and Maximum From Array
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 55% Topics: Array, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def minimumDeletions(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
i, j = nums.index(min(nums)), nums.index(max(nums))
if i > j:
i, j = j, i
return min((i+1)+(len(nums)-j), j+1, len(nums)-i)
Solution from kamyu104/LeetCode-Solutions · MIT