Question: Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. All these operations of SpecialStack must be O(1). To implement SpecialStack, you should only use standard Stack data structure and no other data structure like arrays, list, .. etc.
Example:
Consider the following SpecialStack
16 –> TOP
15
29
19
18
When getMin() is called it should return 15, which is the minimum
element in the current stack.
If we do pop two times on stack, the stack becomes
29 –> TOP
19
18
When getMin() is called, it should return 18 which is the minimum
in the current stack.
Solution :=
Continue reading Design A stack to get minimum in o(1) time.
You must be logged in to post a comment.