Easy C++ Solution using Two pointers || Beats 83%🔥|| O(n) TC & O(1) SC||Alternative BS Approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\nclass Solution {\npublic:\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n\n        int n =(int) arr.size();\n        int h = n-1 , l=0 ;\n        \n        \n        \n        for(int i=h;i>=1;i--)  \n        {\n            if(arr[i]>=arr[i-1] && h>0)\n            {\n                h--;\n            }\n            else break;\n        }\n\n        int res=h;\n\n       for( l=0 ; l<h && (l==0 || arr[l-1]<=arr[l])  ;l++)\n       {\n             \n             while(h<n && arr[l]>arr[h])\n              {\n                 h++;\n              }\n\n\n           res = min(res,h-l-1);\n\n        \n           \n       }\n      return res;\n\n        \n        \n    }\n};\n```\n\n```\n\n\nclass Solution {\npublic:\n\n    bool checker(vector<int> &arr,vector<int> &pref ,vector<int> &suff , int lo,int mid)\n    {\n        int n= (int)arr.size();\n        bool ff =true;\n        int hi = lo+mid-1;\n        if(lo-1>=0 && pref[lo-1]==0) return false;\n        if(hi+1<n && suff[hi+1]==0) return false;\n        if(lo-1>=0 && hi+1<n && arr[lo-1]>arr[hi+1] ) return false;\n        return true;\n    }\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n    \n       int n = (int)arr.size();\n       int ans=n;\n       vector<int> pref(n,0),suff(n,0);\n       pref[0]=1,suff[n-1]=1;\n       for(int i=1;i<n;i++)\n       {\n           if(arr[i]>=arr[i-1] && pref[i-1]==1) pref[i]=1;\n       }\n\n       for(int i=n-2;i>=0;i--)\n       {\n           if(arr[i]<=arr[i+1] && suff[i+1]==1) suff[i]=1;\n       }\n\n       for(int i=0;i<n;i++)\n       {\n           int lo=0,hi=n;\n           while(lo<=hi)\n           {\n               int mid = (lo+hi)/2;\n               if(checker(arr,pref,suff,i,mid))\n               {\n                   ans = min(ans,mid);\n                   hi =mid-1;\n               }\n               else lo = mid+1;\n           }\n       }\n\n       return ans;\n    }\n};\n```\n![4of9h0.jpg](https://assets.leetcode.com/users/images/d5a48e00-497f-4da5-b25d-ca6650410462_1678915207.8747983.jpeg)\n\n\n```
['C++']