Dsa
Stack
Medium
Min Stack with History
Implement a min stack that supports push, pop, top, and retrieving the minimum element in constant time. Additionally, print the history of operations performed on the stack (push and pop).
Input Format:
The first line contains an integer n (number of operations).
Each of the next n lines contains an operation ('push x', 'pop', 'top', 'getMin').
Output Format:
For each operation except 'push', print the result (either the top value, minimum value, or 'None' for pop if the stack is empty). Print the operation history at the end.
Example:
Input:
5
push 3
push 5
getMin
pop
top
Output:
3
5
None
5
Operations history: push(3), push(5), getMin(), pop(), top()
Key concepts
stackmin-stacktracking
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now