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.
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))
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 →
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))