Amazon Coding Interview Question - Min Stack (LeetCode)

preview_player
Показать описание
Here is a step by step explanation of a stack based problem asked at many top tech companies!

Check out my interview prep platform for learning the patterns!

The problem "Min Stack" has been a popular interview question for a long time now asked at top tech companies including Amazon, Google, Bloomberg, and Apple. For this problem, we must extend the functionality of a stack (LIFO) and allow for constant time lookup for the minimum element in our stack.

A common pitfall for this problem is to keep track of the minimum element with a single variable; however, that will not work in the scenario we pop our minimum element. What we must do is create a second stack that keeps track of our minimum every time we add a new element into our original stack.

The time complexity is constant time O(1) and our space complexity is O(N) where N is the number of elements in our stacks.
Рекомендации по теме
Комментарии
Автор

Your videos are so very good, they put everything into the head right away

NextInterviewPrep
Автор

Thanks @Micheal Muinos for these awesome videos. The content is fantastic. Making complex/simple/moderate concepts simple in such a crystal clear manner, and in a very breezy way without excessive jargon. So good while preparing for interviews. You have helped me cement my understanding on things so well

ashwinhariharan
Автор

I love you so much since your explanation always helps me A LOT.

TP-xtsv
Автор

this was nice explanation bro, really loved it!!

chaitanyakarthik
Автор

@
Michael Muinos Thanks a lot for such a great explanation . Could you please upload more frequent videos on leetocode and DSA, it is really very informative to get the concepts from you!

ChandraShekhar-bycd
Автор

You explain really good 👍. Keep it up..
Please solve Sliding window median, Minimum falling path sum. If you have time..

priyanshrastogi
Автор

Awesome.. great explanation.. waiting for more video's.

deepakmarneni
Автор

Thanks a lot for another great video!! I am waiting for more each day. How do you come up with this solution? It's easy to implement but hard to come up with.

yitingg
Автор

need to modify code because empty stack gives error now.

vinoddiwan
Автор

Do we really need to add the same value multiple times? can we just check the "peek()" and if it is less, then we can add right? great explanation and thank you for the videos.

rchukkapalli
Автор

Recently i gave an interview the interviewer ask the same question but he also wants constant space Complexity means without using extra stack. can you please explains this also. Thank You

bhanugupta