Valid Parentheses
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();EasyStack & Monotonic StackLeetCode #20
Valid Parentheses
Stack of opens. On close, top must match. Empty at end.
Examples
Example 1
Input
()
Output
true
Example 2
Input
()[]{}
Output
true
Stuck? Take a nudge
C++17Autosaves