|
241. Implement Stack with Push() Pop() and Mininum() operation in O(1).
Microsoft Interview Questions and Answers
(Continued from previous question...)
241. Implement Stack with Push() Pop() and Mininum() operation in O(1).
Question:
Implement Stack with Push() Pop() and Mininum() operation in O(1).
maybe an answer:
1.suppose we have stack(can be implemented through class),and top(indicates top position of the stack and min which indicates minimum element in stack
2.pop(),push() can be implemented O(1) as usually(since push and pop takes place on top) and for min
whenever we are inserting an element in to stack we update min as
if(element
min=element
else
min=min
(Continued on next question...)
Other Interview Questions
|