Easy C++ O(nlogn)
\nclass Solution {\npublic:\n    int bin_search(int key,int lo,int hi,vector<int>&arr){\n        while(lo < hi){\n            int mid = lo + (hi-lo+1)/2;\n     
```\nclass Solution {\npublic:\n    int bin_search(int key,int lo,int hi,vector<int>&arr){\n        while(lo < hi){\n            int mid = lo + (hi-lo+1)/2;\n            if(arr[mid] <= key){\n                lo = mid;\n            }\n            else{\n                hi = mid-1;\n            }\n        }\n        if(arr[lo] <= key){\n            return lo;\n        }\n        else{\n            return -1;\n        }\n    }\n    int bin_search2(int key,int lo,int hi,vector<int>&arr){\n        while(lo < hi){\n            int mid = lo + (hi-lo)/2;\n            if(arr[mid] >= key){\n                lo = mid + 1;\n            }\n            else{\n                hi = mid;\n            }\n        }\n        if(arr[lo] >= key){\n            return lo;\n        }\n        else{\n            return arr.size();\n        }\n    }\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n        int n = arr.size();\n        int left_inflec = -1;\n        int right_inflec = n;\n        for(int i=0;i<n-1;i++){\n            if(arr[i+1] < arr[i]){\n                left_inflec = i;\n                break;\n            }\n        }\n        for(int i=n-1;i>=1;i--){\n            if(arr[i-1] > arr[i]){\n                right_inflec = i;\n                break;\n            }\n        }\n        cout<<left_inflec<<" "<<right_inflec<<"\\n";\n        if(left_inflec == -1){\n            return 0;\n        }\n        int min1 = INT_MAX;\n        for(int i=right_inflec;i<n;i++){\n            int index = bin_search(arr[i],0,left_inflec,arr);\n            cout<<index<<" "<<i<<"\\n";\n            if(index != -1){\n                min1 = min(min1,i-index-1);\n            }\n        }\n        for(int i=left_inflec;i>=0;i--){\n            int index = bin_search2(arr[i],right_inflec,n-1,arr);\n            cout<<index<<" "<<i<<"\\n";\n            if(index != -1){\n                min1 = min(min1,index-i-1);\n            }\n        }\n        if(min1 == -1)return 0;\n        return min(min1,min(n-left_inflec,right_inflec));\n    }\n};\n```
[]