28. Implement stack using queues
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
This is the standard problem , In this we can create two queue and then -
For push operation, first we push the givem value in queue 2
After that we push all the value of queue 1 in queue 2 ,it will result in the first element will be present at the last of queue
We swap queue 1 and 2 it will result that the first element of queue is the element we just pushed for in queue 2.
Time Complexity: O(n)
Auxiliary Space Complexity: O(n)
because we used an extra queue..
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.