Minimum Element in Stack in O(1) Space
Hard

Problem Statement

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time and using constant extra space.

Examples

1Example 1
Input:
{ "operations": [ "push", "push", "push", "getMin", "pop", "top", "getMin" ], "values": [ -2, 0, -3 ] }
Output:
[ -3, 0, -2 ]
2Example 2
Input:
{ "operations": [ "push", "getMin", "pop", "getMin" ], "values": [ 0 ] }
Output:
[ 0, -1 ]
3Example 3
Input:
{ "operations": [ "push", "push", "getMin", "push", "getMin" ], "values": [ 2147483646, 2147483646, 2147483647 ] }
Output:
[ 2147483646, 2147483646 ]
Loading...

Sign in to Run Code and Submit