LeetCode 155. Min Stack (Algorithm Explained)

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

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

Nick, I'm thinking about becoming a patron, but I noticed your $10 tier has a bad typo. You are spelling tier as "tear." Just a heads-up!

FishTalkFish
Автор

I wrote Python but your explanation totally works for any language. Excellent job!

jiayiwu
Автор

keep it up bro...solve medium and hard problems also bro.👍

ravigupta
Автор

who's here from the coding 30 day challenge

BarbaricDuck
Автор

["MinStack", "push", "push", "push", "getMin", "pop", "getMin"]
[[], [0], [1], [0], [], [], []]
This case does not hold up, nor does if their are similar min values in same order

aniketbhoite
Автор

using 1 stack doesn't really make sense and it just makes it harder to read or understand. In the end the time and space complexity is the same with the 2 stack solution. 2 stack solution is more clear and easier to understand, so I would go with that.

sedat
Автор

bro do it in constant space, every body Seems to be doing it in linear space

jacobblack
Автор

Great Videos . Do you have videos on Hard problems too . If yes how to access then ?

anandlotlikar
Автор

Amazing! crisp, clear and best explanation!

shivangisrivastava
Автор

O(1) time and space solution is possible with a bit of extra math.

tobiaswilfert
Автор

what will happen in the case where multiple getMin() is called multiple times after removing min element using pop() method

vinitsunita
Автор

there is a solution with one stack, space o(n)
formula 2* curr -min, if you could explain it to us

basheeral-momani
Автор

Even using two stacks we'll still have the same space complexity, so what's point.

ramazanchasygov
Автор

Short video time( just 8 min) and clear explanation is always what I want! Thanks.

ZhouHaibo
Автор

Very nice. I didn't think of 2 stacks. That's genius. Best I could think of was a LinkedList and a self balancing sorted binary search tree (to get the minimum). My implementation of the latter beat 70% of solutions so I guess O(Log(N)) Operations is not too bad.

mandy
Автор

Is this video's audio just weird or something? I feel like it feels like you're yelling at me, although I doubt that's the intention.

uHnodnarB
Автор

there is a crazy answer where you do it in o(1) memory LMAO

ahmadmohamad
Автор

I don't get what the point is of doing this but thanks for helping me understand it!

zoeyblaque
Автор

Why am I getting wrong answer if using '==' instead of 'equals' in line 14 of two stack solution??

akshitajain
Автор

For keeping the minimum, I used a variable as well, however if the element being popped from the stack is a minimum then I just recalculate the minimum while I iterate through the element of the stack to place them in a smaller one. For reference, I did not use the stack class but rather resizing integer arrays.

andreioprea