Preview:
def unk(push,popp):
    j=0
    stack=[]
    for i in push:
        stack.append(i)
        while stack and  stack [-1]==popp[j]and len(popp)>j:
            stack.pop()
            j+=1
        
    return not stack
pushed = [1,2,3,4,5]; popped = [4,3,5,1,2]
print(unk(pushed,popped))
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter