Shortest Subarray to Remove for Sorted Order
Remove the shortest contiguous piece so that what is left is sorted.
The problem
Implement Solution.findLengthOfShortestSubarray(arr). You may remove one contiguous subarray from arr (it may be empty). The values that remain, in their original order, must be non-decreasing. Return the length of the shortest subarray you can remove. For example, [1, 2, 3, 10, 4, 2, 3, 5] gives 3: remove [10, 4, 2] to leave [1, 2, 3, 3, 5]. arr has between 1 and 100,000 values, each from 0 to 1,000,000,000.
Starter code
class Solution:
def findLengthOfShortestSubarray(self, arr):
passPublic examples
arr = [1, 2, 3, 10, 4, 2, 3, 5]gives3arr = [1, 2, 0, 3]gives1arr = [9]gives0
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
