MinStack Leetcode

Was doing Min stack (Leetcode https://leetcode.com/problems/min-stack/). Was able to figure out using a second stack. But the top voted answer. Oh my gosh. So elegant and clean. Basically, you use a linked list; in every node, keep track of the min value prior to that node. How do people even figure out such stuff? TC 300k #leetcode

Google ejwuwu Jan 1

You memorize

New
faanglazer Jan 1

Neetcode has a video on it where he explains the thought process

Qualcomm lele re Jan 1

Yeah enough practice and exposure to similar questions helps. Instead of linkedlist, stack, vector can also be used. But essentially you keep track of min elements till now

Informatica infamgr Jan 1

this post made me happy. already knew the linked list approach looking at hyperlink

PayPal fGn8tWp Jan 1

just ask chatgpt to do it for you dafuq are u doin