What are we tryinig to do in this question?

If we are entering elements into the stack then we can directly maintain a variable which gets updated if newer element is smaller, what is the purpose of this approach?

@tusharnitharwal hey ,we have to take minimum rlement from stack itself ,this is problem question ,like pop ,push functions you have to make another function getmin which gives out minimum from stack.Hope you get it :slight_smile:

then why cant we just keep a variable and update it if a smaller number is added. Why do we follow this procedure?

@tusharnitharwal hey ,you have to find minimum in constant space complexity so you can’t take extra variable for that.

isnt the current min function taking extra space?

@tusharnitharwal no extra space is there if you do it with one stack only ,also hme ise stack ki madad se krna hai islie hme min function bnana hai question ka motive yhi hai ,nhi to isse bhi bhut asaan ways hai krne ke ,but acc to question requirement chlna hai .

still not clear. Why cant we just update the value of current min when we input the array?

@tusharnitharwal Bro hme stack bna kr input lena hai ,hme stack ka function bnana hai jisme min hm stack ke operation ke through nikal.ske jo ki push pop top hai ,ye stack based question hai ,hme function bnana ,simply array me to kr hi doge app ,interviewer hmse stack ke prospect me puchega.

and if we are storing some\other value in the stack and not the actual value, then what is the use of that stack?

wouldnt this procedure change the value of the original stack?

@tusharnitharwal bro ye question simply ye hai ,get minimum from stack ,mtlb stack me se min nikalna hai hme stack dia hoga ,aur constant space me krna hai ,hme sirf minimum nikalna hai from stack uske andr kuch bhi value ho usse hme fark nhi pdta.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.