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.
You don't need pop(-1) or pop(0); instead, for the queue data structure, you should use insert(0,n) for the enqueue method. Check my codes.
classSolution:# Write your code heredef__init__(self):self.stack=[]self.queue=[]defpushCharacter(self,ch):self.stack.append(ch)defenqueueCharacter(self,ch):self.queue.insert(0,ch)defpopCharacter(self):returnself.stack.pop()defdequeueCharacter(self):returnself.queue.pop()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 18: Queues and Stacks
You are viewing a single comment's thread. Return to all comments →
You don't need pop(-1) or pop(0); instead, for the queue data structure, you should use insert(0,n) for the enqueue method. Check my codes.