DIY: Min Stack

Solve the interview question "Min Stack" in this lesson.

Problem statement

You have to implement the MinStack type, which has a Min() function. Whenever Min() is called, the minimum value of the stack is returned in O(1) time. The element is not popped from the stack. Its value is simply returned.

Input

The input will be a stream of numbers from which you have to create a min stack.

Output

The output will return the minimum number in O(1) time.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.