class Solution(object):

    def validateStackSequences(self, pushed, popped):
        """
        :type pushed: List[int]
        :type popped: List[int]
        :rtype: bool
        """
        stack = []
        pp_idx = 0
        for ps in pushed:
            if ps != popped[pp_idx]:
                stack.append(ps)
            else:
                pp_idx += 1
                while pp_idx < len(popped) and stack and popped[pp_idx
                    ] == stack[-1]:
                    stack.pop()
                    pp_idx += 1
        return False if stack else True

a26cba1f25845b7c6c475aa6a63d28f074c568ff
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def validateStackSequences(self, pushed, popped):
        """
        :type pushed: List[int]
        :type popped: List[int]
        :rtype: bool
        """
        stack = []
        pp_idx = 0
        for ps in pushed:
            if ps != popped[pp_idx]:
                stack.append(ps)
            else:
                pp_idx += 1
                while pp_idx < len(popped) and stack and popped[pp_idx
                    ] == stack[-1]:
                    stack.pop()
                    pp_idx += 1
        return False if stack else True
