LeetCode ยท Stack

Stack Problem Set

LIFO problems โ€” parentheses matching, monotonic stacks, expression evaluation. When you need to "remember the last thing" or find the next greater/smaller element.

Concept page: Stack
DifficultyPatternProblemKey Insight
EasymatchingLC 20 ยท Valid ParenthesesPush openers, pop and match closers. O(n).
MediumdesignLC 155 ยท Min StackTwo stacks: main + min tracking. O(1) getMin.
MediumevaluationLC 150 ยท Evaluate Reverse Polish NotationPush numbers, pop two on operator, push result. O(n).
MediumgenerationLC 22 ยท Generate ParenthesesBacktracking with open/close counts. O(4โฟ/โˆšn).
MediumnestedLC 394 ยท Decode StringStack of (string, count) pairs for nested encoding. O(n).
MediummonotonicLC 739 ยท Daily TemperaturesMonotonic decreasing stack. Pop when current > top. O(n).
MediummonotonicLC 853 ยท Car FleetSort by position desc, stack tracks arrival times. O(n log n).
HardmonotonicLC 84 ยท Largest Rectangle in HistogramMonotonic increasing stack. Calculate area on pop. O(n).
MediumevaluationLC 227 ยท Basic Calculator IISingle pass + stack. Collapse * and / immediately; defer + and - as signed terms. O(n).

โ† Back to all LeetCode categories