Queue using Two Stacks

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    from collections import deque
    
    stack = deque()
    stack2 = deque()
    
    if __name__ == '__main__':
        n = int(input())
        for i in range(n):
            input_value = input()
            inp = list(map(int, input_value.split()))
            if inp[0] == 1:
                while(stack2):
                    stack.append(stack2.pop())
                obj = inp[1]
                stack.append(obj)
            elif inp[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?