Min Stack (Design)
Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.
Topic refresher: Stack — Last In, First Out
LIFO for matching, undo, and next-greater patterns.
stack<char> st;
for (char c : s) {
if (/* open */) st.push(c);
else {
if (st.empty() || st.top() != need) return false;
st.pop();
}
}
return st.empty();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