Python Solution Based on Binary Search
Time Complexity = O ( N * Log N )\n\n\nclass Solution:\n    def findLengthOfShortestSubarray(self, arr: List[int]) -> int:\n        \n        def lowerbound(lef
Time Complexity = O ( N * Log N )\n\n```\nclass Solution:\n    def findLengthOfShortestSubarray(self, arr: List[int]) -> int:\n        \n        def lowerbound(left, right, target):\n            while left < right:\n                mid = left + (right - left) // 2\n                \n                if arr[mid] == target:\n                    right = mid\n                elif arr[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid\n                \n            return left\n        \n        \n        N = len(arr)\n        \n        # find the longest ascending array on the left side\n        i = 0\n        while i + 1 < N and arr[i] <= arr[i+1]:\n            i += 1\n        \n        if i == N - 1:\n            # it is already in ascending order\n            return 0\n        \n        # find the longest ascending array on the right side\n        j = N - 1\n        while j - 1 >= 0 and arr[j] >= arr[j-1]:\n            j -= 1\n        \n        if j == 0:\n            # the entire array is in decending order\n            return N - 1\n        \n        # keep ascending array on right side or left side\n        result = min(N - (N - j), N - i -1)\n        \n        \n        # find the shortest unordered subarray in the middle \n        for k in range(i+1):\n            l = lowerbound(j, len(arr), arr[k])\n            result = min(result, l - (k + 1))\n        \n        \n        return result\n\n```
['Binary Tree', 'Python', 'Python3']