Beginner-friendly! O(n) O(1) Solution Detailed textual explanation
IntuitionBeginner-friendly！ApproachCore idea: Divide the array into three parts. The middle part is to be deleted, and after deletion, the entire array becomes
# Intuition

**Beginner-friendly！**

# Approach

**Core idea: Divide the array into three parts. The middle part is to be deleted, and after deletion, the entire array becomes non-decreasing.
Both the left and right parts should be non-decreasing.**
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:$$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def findLengthOfShortestSubarray(self, arr: List[int]) -> int:
        ans = 0
        n = len(arr)
        r = n - 1  # Start searching from the far right
        
        # Compare the current value of r with the value before it 
        # (to find the right breakpoint after deletion)
        while r >= 1 and arr[r] >= arr[r - 1]:
            r -= 1  # r >= 1 ensures no out-of-bounds error 
                    # (e.g., when r = 0, r - 1 causes an error).
        
        # If r == 0, this means the entire array is non-decreasing.
        # Return 0 because no deletion is needed.
        if r == 0:
            return 0
        
        # Initialize the answer as r, assuming the worst case 
        # where the entire left part is non-decreasing and must be deleted.
        ans = r
        l = 0  # Start marking the left breakpoint
        
        # l == 0 is a special case;
        # arr[l - 1] <= arr[l] ensures we are checking the first non-decreasing part.
        while l == 0 or arr[l - 1] <= arr[l]:
            # r < n ensures no out-of-bounds error;
            # the second condition checks if the left and right parts cannot be merged.
            while r < n and arr[r] < arr[l]:
                r += 1  # Move the right breakpoint to find a position 
                        # where the left and right parts can merge.
            
            # After exiting the two while loops, the left part is non-decreasing,
            # the third part (right segment) has already been proven to be non-decreasing,
            # and the merged array is also non-decreasing after deletion.
            # Thus, the middle part to be deleted is calculated as r - l - 1.
            # Example: When the first part before index 1 and the third part after index 3
            # are both non-decreasing and they can merge, the length to be deleted is 1, 
            # calculated as 3 - 1 - 1.
            ans = min(ans, r - l - 1)
            
            l += 1  # Continue moving the left breakpoint to explore all possible scenarios 
                    # and find the optimal solution.
        
        return ans 
        
```
['Two Pointers', 'Sliding Window', 'Python3']