classSolution:defvalidateStackSequences(self,pushed: List[int],popped: List[int]) ->bool: stack = [] left, right =0,0while left <len(pushed): stack.append(pushed[left]) left +=1while stack and stack[-1]== popped[right]: stack.pop() right +=1returnTrueifnot stack elseFalse