Implement Queue using Stacks (LeetCode 232) | Side by side demo and diagrams

preview_player
Показать описание


Chapters:
00:00 - Intro
00:52 - Problem Statement and Description
02:52 - Side by side demo
10:21 - Dry-run of Code
13:57 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

Whenever I see your video related to DSA, I am satisfied with the concept.

manojtate
Автор

nice explanation with visuals and clear understanding, love this.

sdkaraarslan
Автор

please make a playlist on Stack, queue, HashTables tries etc. as your teaching is awesome please continue your ds playlist

GAGGZz
Автор

You have playlists on all other data structures
Can you make a playlist on stacks & queues too?

Blackswordsman
Автор

nice please make playlist for linked-list.. lot's of people are struggling in linked-list..
Thanks!

sonuanand
Автор

class MyQueue {
private Stack<Integer> input;
private Stack<Integer> output;

public MyQueue() {
this.input = new Stack<>();
this.output = new Stack<>();
}

public void push(int x) {
input.push(x);
}

public int pop() {
if (!output.isEmpty())
return output.pop();
while(!input.isEmpty()){
output.push(input.pop());
}
return output.pop();
}

public int peek() {
if (output.isEmpty())
while (!input.isEmpty())
output.push(input.pop());
return output.peek();
}

public boolean empty() {
return (input.isEmpty() && output.isEmpty());
}
}

// thank me later!

sumitraj