Implement Stack Using Queues | LeetCode 225 (Costly Push) | Coding Interview Tutorial

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

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

💲 All coupons and discounts 💲

Implement Stack Using Queues | LeetCode 225 (Costly Push) | Coding Interview
#implementstackusingqueues #leetcode #algorithms #terriblewhiteboard #codinginterview

Click the time stamp to jump to different parts of the video.
00:00 Title
00:06 Whiteboard solution
04:18 Coding solution
08:50 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
Автор

The intro music reminds me of Gucci Flip Flops.

punstress
Автор

I get a runtime error when I copy and paste your solution onto leetcode that says "Queue has already been defined"

hideinbush
Автор

Day 1/40 challenge: I was a little stuck on figuring out the logic on paper, so I took a peek at your whiteboard solution. The use of 2 queues made sense to me after that so I got to work on my own solution. Not sure if my approach is unconventional, but I was able to get the solution without making making a helper class like your class Queue.

Within the main function I am able to initialize it like below:
var MyStack = function () {
this.firstQueue = [];
this.secondQueue = [];
};

Within my other methods I do use, push() and .pop() array methods though. For example:

MyStack.prototype.push = function (x) {
this.secondQueue.push(x);
while (this.secondQueue.length > 0) {

}
};

During an interview would that be allowed? I don't see you use any array methods for your solution.

IRLVaporwave