CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsStack & Monotonic Stack

Min Stack (Design)

Medium
LeetCode
2/3
MediumStack & Monotonic StackLeetCode #155

Min Stack

Support push/pop/top/getMin in O(1). Keep a parallel min stack.

Examples

Example 1

Input

push -2
push 0
push -3
getMin
pop
top
getMin

Output

-3
0
-2

Stuck? Take a nudge

C++17Autosaves