Stack Quiz Doubt

Here is the question:-
Q1. Minimum In A Stack
In what minimum time complexity you can compute minimum at any state of stack?

O(1)

O(n)

O(n^2)
How is the time complexity is O(1), because if the size of stack at the current is n, then we need to run a while to check which is the minimum element in the stack.

hello @Sakshi2004

we can use additional stack which store minimum till every state . and using that we can answer in O(1)

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.