0 ms | Beats 100%
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n        int n = arr.size();\n        int l=0,r=n-1;\n  
![image.png](https://assets.leetcode.com/users/images/0ea1d698-4e17-479a-a1eb-b27a754caeaf_1731653649.9752247.png)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n        int n = arr.size();\n        int l=0,r=n-1;\n        while(l+1<n && arr[l] <= arr[l+1]) l++;\n        if(l==n-1) return 0;\n        while(r-1>=0 && arr[r] >= arr[r-1]) r--;\n        int res = min(n-l-1,r),i=0,j=r;\n        while(i<=l && j<n){\n            if(arr[i] <= arr[j]){\n                res = min(res,j-i-1);\n                i++;\n            }else{\n                j++;\n            }\n        } \n        return res;\n    }\n};\n```\n![Please hit the upvote button (1).png](https://assets.leetcode.com/users/images/5dda48a3-e790-4513-b706-84aa70965a01_1731654135.6788218.png)\n
['Array', 'Two Pointers', 'C++']