python sliding window
first use loop to find the left and right bound where that element must be excluded\nthen use sliding window to find best i for each j\n\n\n\n\tclass Solution(o
first use loop to find the left and right bound where that element must be excluded\nthen use sliding window to find best i for each j\n\n\n\n\tclass Solution(object):\n\t\tdef findLengthOfShortestSubarray(self, arr):\n\t\t\t"""\n\t\t\t:type arr: List[int]\n\t\t\t:rtype: int\n\t\t\t"""\n\t\t\tn = len(arr)\n\t\t\tif n<=1: return 0\n\t\t\tl,r = n,-1\n\n\t\t\tfor i in range(1,n):\n\t\t\t\tif arr[i]<arr[i-1]:\n\t\t\t\t\tl = i\n\t\t\t\t\tbreak\n\t\t\t# monotonicially increasing\n\t\t\tif l == n: return 0\n\n\t\t\tfor j in range(n-2,-1,-1):\n\t\t\t\tif arr[j]>arr[j+1]:\n\t\t\t\t\tr = j\n\t\t\t\t\tbreak\n\n\t\t\t# you can delete all to the left of r (including r)\n\t\t\t# you can also delete all to the right of l (including l)\n\t\t\tans = min(r+1,n-l)\n\n\t\t\ti = 0\n\t\t\t# sliding window, find the rightmost i for each j\n\t\t\t# note at all time i must be less than l\n\t\t\tfor j in range(r+1,n):\n\t\t\t\twhile i<l and arr[i] <= arr[j]:\n\t\t\t\t\ti += 1\n\t\t\t\tans = min(ans,j-i)\n\t\t\treturn ans\n\n
[]