C++ with picture, O(n)
Intuition\nI initially thought this was an LCS variation. It took me a few WAs to go back and re-read the problem description :( :(\n\nThen I realized that we n
**Intuition**\nI initially thought this was an LCS variation. It took me a few WAs to go back and re-read the problem description :( :(\n\nThen I realized that we need to remove a *continuous* subarray. So, we basically cut off the middle of the array, leaving left and right parts that forms a non-decreasing sequence.\n\nSo, we can break this problem into the following subproblems:\n1. Find the longest non-decreasing *continuous* subarray starting from the left.\n2. Find the longest subarray ending at the right.\n3. Make the longest non-decreasing sequence from the left and right array. \n\nIn the picture below, you can see left and right subarrays, and two ways to connect them in a non-decreasing sequence.\n![image](https://assets.leetcode.com/users/images/664520ed-02ef-49e1-9976-719ffc272002_1599852991.4627557.png)\n\n**Algorithm**\nWe can use the two pointers pattern to find the best split between left and right subarrays:\n- First, find out the longest non-increasing sequence in the right part of the array. `r` will point to the first element of that sequence.\n- Now, go left-to-right, and for each `l` increment `r` while n[r] < n[l]. \n\t\t- Track the minimum length between left and right in `res`.\n- Break if `n[l] < n[l - 1]`. The left sequence is no longer non-decreasing.\n\n```cpp\nint findLengthOfShortestSubarray(vector<int>& n) \n{\n    int sz = n.size(), r = sz - 1;\n    for (; r > 0 && n[r - 1] <= n[r]; --r) ;\n    auto res = r;\n    for (int l = 0; l < r && (l == 0 || n[l - 1] <= n[l]); ++l) {\n        while (r < sz && n[r] < n[l])\n            ++r;\n        res = min(res, r - l - 1);\n    }\n    return res;\n}  \n```
[]