You are viewing a single comment's thread. Return to all comments →
You are right, but somehow, I felt it "ok" to do that.
Still, you can handle that with minor change, just by using one extra variable.
Here's the modified code for you :
old, new = [], [] for _ in range(int(input())): val = list(map(int,input().split())) if val[0] == 1: if not new : # Row added first = val[1] # Row added 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 first)
Thanks for bringing this up !
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 →
You are right, but somehow, I felt it "ok" to do that.
Still, you can handle that with minor change, just by using one extra variable.
Here's the modified code for you :
Thanks for bringing this up !