We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTfromcollectionsimportdequestack=deque()stack2=deque()if__name__=='__main__':n=int(input())foriinrange(n):input_value=input()inp=list(map(int,input_value.split()))ifinp[0]==1:while(stack2):stack.append(stack2.pop())obj=inp[1]stack.append(obj)elifinp[0]==2:while(stack):stack2.append(stack.pop())stack2.pop()else:while(stack):stack2.append(stack.pop())to_print=stack2.pop()print(to_print)stack2.append(to_print)
I'm getting time limit exceeded. Any idea?
Cookie support is required to access HackerRank
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 →
I'm getting time limit exceeded. Any idea?