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.
My initial code was timing out on some of the test cases. This was because on Command == 2, I was pushing all values from S1 -> S2 and then from S2 -> S1.
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Java code passes 100%
My initial code was timing out on some of the test cases. This was because on Command == 2, I was pushing all values from S1 -> S2 and then from S2 -> S1.
And on Command == 3, I had to do the same in order to get the front element, push items from S1 -> S2 and then S2 -> S1. Very inefficient..
I hope this helps!