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.
This is not true. In 2 stack queue implementation, cost of the insert operation is O(1). So complexity of inserting q-1 elements is O(q). Cost of peek (top , front) operation is O(q). Therefore complexity of inserting q-1 elements and printing front element is O(q).
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 →
This is not true. In 2 stack queue implementation, cost of the insert operation is O(1). So complexity of inserting q-1 elements is O(q). Cost of peek (top , front) operation is O(q). Therefore complexity of inserting q-1 elements and printing front element is O(q).