Class Solution
java.lang.Object
g2001_2100.s2091_removing_minimum_and_maximum_from_array.Solution
2091 - Removing Minimum and Maximum From Array.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> array of <strong>distinct</strong> integers <code>nums</code>.</p>
<p>There is an element in <code>nums</code> that has the <strong>lowest</strong> value and an element that has the <strong>highest</strong> value. We call them the <strong>minimum</strong> and <strong>maximum</strong> respectively. Your goal is to remove <strong>both</strong> these elements from the array.</p>
<p>A <strong>deletion</strong> is defined as either removing an element from the <strong>front</strong> of the array or removing an element from the <strong>back</strong> of the array.</p>
<p>Return <em>the <strong>minimum</strong> number of deletions it would take to remove <strong>both</strong> the minimum and maximum element from the array.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2, <strong>10</strong> ,7,5,4, <strong>1</strong> ,8,6]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong></p>
<p>The minimum element in the array is nums[5], which is 1.</p>
<p>The maximum element in the array is nums[1], which is 10.</p>
<p>We can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back.</p>
<p>This results in 2 + 3 = 5 deletions, which is the minimum number possible.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [0, <strong>-4</strong> , <strong>19</strong> ,1,8,-2,-3,5]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>The minimum element in the array is nums[1], which is -4.</p>
<p>The maximum element in the array is nums[2], which is 19.</p>
<p>We can remove both the minimum and maximum by removing 3 elements from the front.</p>
<p>This results in only 3 deletions, which is the minimum number possible.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [<strong>101</strong> ]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<p>There is only one element in the array, which makes it both the minimum and maximum element.</p>
<p>We can remove it with 1 deletion.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
<li>The integers in <code>nums</code> are <strong>distinct</strong>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumDeletions
public int minimumDeletions(int[] nums)
-