Logo
Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

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

  1. Example 1:

    • Input: [3, 2, 5, 1, 4]
    • Expected Output: 3
    • Justification: The smallest element is 1 and the largest is 5. Removing 4, 1, and then 5 (or 5, 4, and then 1) in three moves is the most efficient strategy.
  2. Example 2:

    • Input: [7, 5, 6, 8, 1]

.....

.....

.....

Like the course? Get enrolled and start learning!