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.
What are the benefits to using two stacks for this as opposed to one? I wrote it with one stack and was able to pass all the tests, but i'm assuming my design is inefficient in some way? Or just not the point of this problem? Just feel like i'm missing something because I didn't expect mine to pass with only one stack, just tried it for fun.
Current complexity with one queue is O(n) complexity for dequeue from popping the first element/shifting the rest, O(1) for both enqueue and print.
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 →
What are the benefits to using two stacks for this as opposed to one? I wrote it with one stack and was able to pass all the tests, but i'm assuming my design is inefficient in some way? Or just not the point of this problem? Just feel like i'm missing something because I didn't expect mine to pass with only one stack, just tried it for fun.
Current complexity with one queue is O(n) complexity for dequeue from popping the first element/shifting the rest, O(1) for both enqueue and print.