Implement Queue Using Stacks | LeetCode 232 | Coding Interview Tutorial

preview_player
Показать описание
Implement Queue Using Stack solution: LeetCode 232

AFFILIATE LINKS
If you're interested in learning algorithms, these are great resources.

💲 All coupons and discounts 💲

Implement Queue Using Stacks | LeetCode 232 | Coding Interview
#implementqueueusingstacks #leetcode #algorithms #terriblewhiteboard #codinginterview

Click the time stamp to jump to different parts of the video.
00:00 Title
00:06 Problem readout
02:30 Whiteboard solution
06:15 Coding solution
09:51 Result and outro
Рекомендации по теме
Комментарии
Автор

If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

TerribleWhiteboard
Автор

I like your methods, but for some reason it's not registering with me. I took a more naive approach with push() and pop():

push = function (x) {
while (this.primary.size() > 0) {

}

this.secondary.push(x);

while (this.secondary.size() > 0) {

}
};

pop = function () {
while (this.primary.size > 1) {

}
const popped = this.primary.pop();

while (this.secondary.size() > 0) {

}

};

It makes the peek() method more simplified though:

peek = function () {
return this.primary.peek();
};

I'll come back to this and try to make sure I get it with your more efficient way.

IRLVaporwave
visit shbcf.ru