28. Implement stack using queues
The problem can be found at the following link: Question Link
My Approach
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 and Auxiliary Space Complexity
Time Complexity:
O(n)
Auxiliary Space Complexity:
O(n)
because we used an extra queue..
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. 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 rishabhv12/Daily-Leetcode-Solution repository.
Last updated