snippets/stack_removal_order_checker.py

9 lines
238 B
Python

def check(in_list: list, out_list: list) -> bool:
stack = []
i = 0
for num in in_list:
stack.append(num)
while stack and stack[-1] == out_list[i]:
stack.pop()
i += 1
return not stack