Python O(N) using stack
Insert the increasing sequence at the end of the array into stack. For each element at index i, empty stack till arr[i] is less than equal to the element at the
Insert the increasing sequence at the end of the array into stack. For each element at index i, empty stack till arr[i] is less than equal to the element at the top of stack\n\n```\nclass Solution(object):\n    def findLengthOfShortestSubarray(self, arr):\n        stack = [[len(arr)-1, arr[-1]]]\n        \n        for i in range(len(arr)-2, -1, -1):\n            if arr[i] <= arr[i+1]:\n                stack.append([i, arr[i]])\n            else:\n                break\n        \n        min_len = len(arr)-len(stack)\n        \n        for i in range(len(arr)):\n            if i == 0 or arr[i] >= arr[i-1]:\n                while len(stack) > 0 and (stack[-1][1] < arr[i] or stack[-1][0] <= i):\n                    stack.pop()\n\n                if len(stack) > 0:\n                    min_len = min(min_len, stack[-1][0]-i-1)\n                else:\n                    min_len = min(min_len, len(arr)-i-1)\n            else:\n                break\n        \n        return min_len
[]