Python: heuristic 2 stacks approach (624 - 652 ms)
The main idea is to find two non-decreasing subarrays from the left end and the right end and then merge them to find the maxmimum sequences over all possible c
The main idea is to find two non-decreasing subarrays from the left end and the right end and then *merge* them to find the maxmimum sequences over all possible combinations. We use two stacks to keep track of these two non-decreasing subarrays.\n```python\ndef findLengthOfShortestSubarray(self, arr):\n        # 2 stacks\n\n        n = len(arr)\n        arr = [0] + arr + [float("inf")]\n        A, B = [], []\n        p, q = 1, len(arr)-2 #p: left end, q: right end \n\n        M = 0 \n        while p <= q:\n            if arr[p-1] <= arr[p]:\n                A.append(arr[p])\n                p += 1\n            elif arr[q] <= arr[q+1]:\n                B.append(arr[q])\n                while A and A[-1] > B[-1]: # pop out numbers in A to merge\n                    A.pop()\n                q -= 1\n            else:\n                break\n\n            M = max(M, len(A)+len(B))\n\n        return n - M \n```\n**Remark:** One should try two more test cases: `[1,2,3,4,5,10,1,6,7,8,9,10]` and `[1,2,3,10,0,7,8,9]` to further verify one\'s code is correct.
['Stack', 'Python']