Practice Shortest Subarray to be Removed to Make Array Sorted
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#1574
LeetCode ProblemShortest Subarray to be Removed to Make Array Sorted
Problem Statement
Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing. Return the length of the shortest subarray to remove. A subarray is a contiguous subsequence of the array.
Source: Shortest Subarray to be Removed to Make Array Sorted on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [1,2,3,10,4,2,3,5]
Output
3
# Example 2
Input
arr = [5,4,3,2,1]
Output
4
# Example 3
Input
arr = [1,2,3]
Output
0
Constraints
1 <= arr.length <= 10^5
0 <= arr[i] <= 10^9
Related LeetCode Problems
Practice more problems similar to Shortest Subarray to be Removed to Make Array Sorted.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.