2 Pointer Approach | Java [ 1ms ] | O(n) Time Complexity + O(1) Space Complexity | Easy 2 Understand
\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int n=arr.length;\n        int i=0,j=n-1;\n        \n        while(i<j && 
```\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int n=arr.length;\n        int i=0,j=n-1;\n        \n        while(i<j && arr[i]<=arr[i+1]){\n            i++;\n        }\n        if(i==n-1) return 0;\n        \n        while(j>0 && arr[j]>=arr[j-1]){\n            j--;\n        }\n        \n        if(j==0) return j;\n        \n        int res=Math.min(n-1-i,j);\n        \n        int s=0;\n        \n        while(s<=i && j<n){\n            if(arr[s]<=arr[j]){\n                res=Math.min(res,j-s-1);\n                s++;\n            }\n            else{\n                j++;\n            }\n        }\n        \n        return res;\n    }\n}\n\n```\n```
[]