Min Stack Problem Statement
Design a special stack that supports the following operations in constant time:
Push(num)
: Insert the given number into the stack.Pop
: Remove and return the top element from the stack; return -1 if the stack is empty.Top
: Return the top element of the stack; return -1 if the stack is empty.getMin
: Return the minimum element in the stack; return -1 if the stack is empty.
Example:
Input:
1
5
1 1
1 2
4
2
3
Output:
1 2 1
Explanation:
Initially, the stack is empty.
1. Push 1: Stack becomes [1].
2. Push 2: Stack becomes [2, 1].
3. getMin: Minimum is 1.
4. Pop: Topmost is 2, stack becomes [1].
5. Top: Topmost is 1.
Constraints:
1 ≤ T ≤ 1000
1 ≤ N ≤ 100000
ΣN ≤ 200000
1 ≤ X ≤ 109
Be the first one to answer
Add answer anonymously...
Top Jio Platforms Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Jio Platforms Software Developer
>
Jio Platforms Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app