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
Neetcode has a video on it where he explains the thought process
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
this post made me happy. already knew the linked list approach looking at hyperlink
just ask chatgpt to do it for you dafuq are u doin
You memorize