Leetcode Problem 2091. Removing Minimum and Maximum From Array
2091. Removing Minimum and Maximum From Array
Leetcode Solutions
Optimal Deletions from Front, Back, or Both Ends
Initialize variables to store the indices of the minimum and maximum elements.
Iterate through the array to find the indices of the minimum and maximum elements.
Calculate the number of deletions if we remove elements from the front only, which is the maximum of the indices of the minimum and maximum elements plus one.
Calculate the number of deletions if we remove elements from the back only, which is the size of the array minus the minimum of the indices of the minimum and maximum elements.
Calculate the number of deletions if we remove elements from both ends, which is the sum of the index of the minimum element plus one and the size of the array minus the index of the maximum element.
Return the minimum of the three calculated values.