1
# Runtime: 250 ms (Top 81.05%) | Memory: 16.2 MB (Top 5.39%)2
# lets start adding elements to stack. We have to fin the min length [a, b] interval (corresponding to the problem description).3
# a has to be the first element's index we pop from the array. lets say y is the last element's index we pop.4
# and max_pop is the maximum element(not index) we pop during stacking.After stacking process is done we are going to have5
# last elements in the stack E(E is the stack after stacking is done).We have to find M = maximum_element(max_pop, all elements of E)6
# Index of M is going to be right edge of the [a, b] interval10
def findUnsortedSubarray(self, nums) -> int:14
max_pop = float("-inf")15
for i in range(len(nums)):16
while stack and nums[i] < stack[-1][0]:25
stack.append([nums[i], i])30
if min_index == len(nums):32
return max_r - min_index + 1