Implementing a Queue using Stacks - The Easy Solution!!

preview_player
Показать описание
Queues and Stacks are two seemingly different types of data structures. Queues are FIFO (First In First Out) whereas Stacks are LIFO (Last in First Out)

So implementing a Queue using stacks seems a little odd.

Except it isn't.

You can easily use multiple Stacks to implement a Queue interface.

You can find the code at the below link. It is for Javascript. However, the concept remains the same irrespective of the programming language.

Moreover, the solution also runs in amortized O(1) time complexity.

#stacks #queues #algorithms #datastructures #interviewquestions

++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++
Рекомендации по теме
Комментарии
Автор

Great Post Saurabh, Looking forward to more of such posts. Keep it Up !!

sheetgautam
Автор

Waiting for next video....awsm concept 😊

ayushijoshi
Автор

Perfect solution to this problem for the next DSA concept

ShikhaSharma-rily
Автор

Very informative post. Waiting for more conceptual post like this. Great work. 👍😊

errajniparmar
Автор

Nice video....Looking for more interview questions on data structures..

sangeetasharma