[C++] - 2 pointer - O(N) - With explanation
Basically the array to be removed cannot lie in the start, cannot lie in the end and has to be in the middle. Find the largest increasing subarray from front an
**Basically the array to be removed cannot lie in the start, cannot lie in the end and has to be in the middle. Find the largest increasing subarray from front and largest increasing subarray from back. Then how much of back increasing array can be added to largest front increasing array and how much of front increasing array can be added to back increasing array. The largest possible remaining array will be the maximum of these two. Therefore answer is n-max of these two.**\n\n```\n// Basically the array to be removed cannot lie in the start, cannot lie in the end and has to be in the middle. Find the largest increasing subarray from front and largest increasing subarray from back. Then how much of back increasing array can be added to largest front increasing array and how much of front increasing array can be added to back increasing array. The largest possible remaining array will be the maximum of these two. Therefore answer is n-max of these two.\n\n//2 POINTER METHOD - O(N)\n\nclass Solution {\npublic:\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n        int ans,n=arr.size();\n        int p1=0,p2=n-1,i;\n        while(p1<n-1 && arr[p1+1]>=arr[p1]){\n            p1++;\n        }\n        \n        while(p2>0 && arr[p2-1]<=arr[p2]){\n            p2--;\n        }\n        \n        int leftele=arr[p1],pos1=-1;\n        \n        \n        int lmax=p1+1,rmax=n-p2;\n        \n        for(i=p2;i<n;i++){\n            if(arr[i]>=leftele){\n                pos1=i;\n                break;\n            }\n        }\n        \n        if(pos1!=-1){\n            lmax+=n-pos1;           \n        }\n        \n        int rightele=arr[p2],pos2=-1;\n        for(i=p1;i>=0;i--){\n            if(arr[i]<=rightele){\n                pos2=i;\n                break;\n            }\n        }\n        \n        if(pos2!=-1){\n            rmax+=(pos2+1);           \n        }\n        \n        \n        return max(0,n-max(lmax,rmax));\n    }\n};\n```
[]