Back to course home
0% completed
Vote For New Content
Removing Minimum and Maximum From Array (medium)
Problem Statement
Determine the minimum
number of deletions
required to remove the smallest and the largest elements from an array of integers.
In each deletion
, you are allowed to remove either the first (leftmost)
or the last (rightmost)
element of the array.
Examples
-
Example 1:
- Input:
[3, 2, 5, 1, 4]
- Expected Output:
3
- Justification: The smallest element is
1
and the largest is5
. Removing4
,1
, and then5
(or5
,4
, and then1
) in three moves is the most efficient strategy.
- Input:
-
Example 2:
- Input:
[7, 5, 6, 8, 1]
- Expected Output:
2
- Justification: Here,
1
is the smallest, and8
is the largest. Removing1
and then8
in two moves is the optimal strategy.
- Input:
-
Example 3:
- Input:
[2, 4, 10, 1, 3, 5]
- Expected Output:
4
- Justification: The smallest is
1
and the largest is10
. One strategy is to remove2
,4
,10
, and then1
in four moves.
- Input:
Constraints:
- 1 <= nums.length <= 10<sup>5</sup>
- -10<sup>5</sup> <= nums[i] <= 10<sup>5</sup>
- The integers in nums are distinct.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible