You are viewing a single comment's thread. Return to all comments →
Solution using two stacks "old" and "new" in Python :
old, new = [], [] for _ in range(int(input())): val = list(map(int,input().split())) if val[0] == 1: new.append(val[1]) elif val[0] == 2: if not old : while new : old.append(new.pop()) old.pop() else: print(old[-1] if old else new[0])
Logic :
new
old
dequeue
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Solution using two stacks "old" and "new" in Python :
Logic :
new
.old
(point 3 if empty).new
toold
ifold
is empty (if need todequeue
).