class Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
stack = []
left, right = 0, 0
while left < len(pushed):
stack.append(pushed[left])
left += 1
while stack and stack[-1] == popped[right]:
stack.pop()
right += 1
return True if not stack else False