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.
- Queue using Two Stacks
- Discussions
Queue using Two Stacks
Queue using Two Stacks
Sort by
recency
|
29 Discussions
|
Please Login in order to post a comment
Java
C++ Using a second stack to reverse the stack for poping/displaying first element just gives TLE for many testcases. Seems like problem design issue, editorial explain same logic also.
Otherwise a vector is obviously faster to at least display the first element, but that wasnt the task I guess. (Ofc pop_front is still o(n))
There is a really easy way to do this if you use an array, but it can be very ineffient for larger queues. Here what I suggest using as a framework for python code in order to actually try out coding with 2 stacks to simulate a proper queue:
i don't really understand why it's asking to do it with 2 stacks
My answer in Python