Simple Intuition and Approach, C++, Beats 100% submissions
Intuition\nSince we need to remove a subarray, answer will be either a prefix, suffix or some part of prefix + some part of suffix. \nPS: If we can remove any s
# Intuition\nSince we need to remove a **subarray**, answer will be either a prefix, suffix or some part of prefix + some part of suffix. \nPS: If we can remove any **subsequence**, in that case answer will **n - LIS.** \n\n# Approach\nl -> index where longest non-decreasing prefix ends. \nr -> index where longest non-decreasing suffix starts. \n\nNow we cannot just remove subarray(l + 1, r - 1), because of the possibility arr[l] > arr[r]. \nEx. 1 2 3 4 **5** 4 **3** 4 5 6 \nNow we will iterate from 0 to l, and check for the condition arr[r] >= arr[i]. We will keep on incrementing r until we find this condition true and update the answer accordingly. \n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n    void print(vector<int> &arr) {\n        for (auto it: arr) {\n            cout << it << \' \'; \n        }\n        cout << \'\\n\'; \n    }\n\n    int findLengthOfShortestSubarray(vector<int>& arr) {\n        int n = arr.size(); \n        int l = 1, r = n - 2; \n        while (l < n && arr[l] >= arr[l - 1]) {\n            l++; \n        }\n        l--; \n        while (r >= 0 && arr[r] <= arr[r + 1]) {\n            r--; \n        }\n        r++; \n        if (l >= r) {\n            return 0; \n        }\n        int ans = min(n - l - 1, r);\n        int i = 0; \n        while (i <= l) {\n            while (r < n && arr[r] < arr[i]) {\n                r++; \n            }\n            ans = min(ans, r - i - 1); \n            i++; \n        }\n        return ans; \n    }\n};\n```
['C++']