Simple two pointer approach | Easy to understand | Beats 90%
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class Solution {
    public int findLengthOfShortestSubarray(int[] a) {
        int n = a.length;
        
        int i = 0;
        while (i+1<n && a[i] <= a[i+1]) {
            i++;
        }
        
        if (i == n-1) return 0;
        
        int j = n-1;
        while (j>0 && a[j-1] <= a[j]) {
            j--;
        }
        
        int minRemove = Math.min(n-i-1, j); 
        
        int left = 0, right = j;
        while (left <= i && right < n) {
            if (a[left] <= a[right]) {
                minRemove = Math.min(minRemove, right-left-1);
                left++;
            } else {
                right++;
            }
        }
        
        return minRemove;
    }
}
```
['Two Pointers', 'Java']