DIY: Min Stack
Understand how to implement a min stack that efficiently returns the minimum value in constant time. Explore designing push, pop, and min functions, and learn how to create a stack that preserves minimum retrieval without removing elements. This lesson equips you to solve common stack problems in coding interviews.
We'll cover the following...
We'll cover the following...
Problem statement
You have to implement the minStack class, 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 ...