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 STDOUTn=int(input())classQueue:def__init__(self):self.items=[]defenqueue(self,value):self.items.append(value)defdequeue(self):ifself.is_empty():return"Add some value to the Queue"self.items=self.items[1:]defget_head(self):ifself.is_empty():return"Empty Queue"returnself.items[0]defsize(self):returnlen(self.items)defis_empty(self):returnlen(self.items)==0queue=Queue()for_inrange(n):args=list(map(int,input().split()))iflen(args)>1:queue.enqueue(args[1])else:arg=args[0]ifarg==2:queue.dequeue()elifarg==3:print(queue.get_head())
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 →
python sol. with lists: