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 was a great learning experience and I want to share it with you.
First of all this is an exercise and in practice it is slow as it is O(1) for enqueue and O(n) for dequeuing. A more optimal solution would be to use the linked list data structure.
Second of all please watch this video as it helped me wrap my mind around the core concept: https://www.youtube.com/watch?v=AN0axYeLue0. All rights reserved to the creator.
Thirdly, have fun with it and try to go through my solution step by step. It is by no means the best implementation but it passes the tests in a decent amount of time.
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
C++
This was a great learning experience and I want to share it with you.
First of all this is an exercise and in practice it is slow as it is O(1) for enqueue and O(n) for dequeuing. A more optimal solution would be to use the linked list data structure.
Second of all please watch this video as it helped me wrap my mind around the core concept: https://www.youtube.com/watch?v=AN0axYeLue0. All rights reserved to the creator.
Thirdly, have fun with it and try to go through my solution step by step. It is by no means the best implementation but it passes the tests in a decent amount of time.
Good luck with your learning!