You are given an array of integers.
You are allowed to remove one continuous part (subarray) from it.
Your goal is that the remaining array should be in non-decreasing (sorted) order.
Return the minimum length of the subarray you need to remove.
Removing an empty subarray is allowed — which means if the array is already sorted, answer is 0.
Input: arr = [2, 3, 9, 8, 7, 10]
Output: 3
Explanation:
Remove [9, 8, 7], remaining → [2, 3, 10] which is sorted.
Input: arr = [4, 5, 6, 7]
Output: 0
Explanation:
Already sorted → nothing to remove.
Input: arr = [10, 8, 6, 4, 2]
Output: 4
Explanation:
Only one element can remain sorted, so remove 4 elements.
Accepted:
Submission: