Topic
Stack interview questions
All 16 Stack problems from the curated set, easiest first — a core topic for 8 of the 29 engineering roles.
- Easy
- 2
- Medium
- 11
- Hard
- 3
- Sheets
- 3
What Stack is
Updated 2026-09-09A stack is a vertical pile of cafeteria trays where items enter and depart from one single opening at the top. The most recent item set down is the first one retrieved, while items deposited earlier remain buried underneath until newer arrivals are lifted away. This strict last-in, first-out sequence guarantees that older context stays preserved until all newer nested actions run to completion.
When to reach for it
Reach for a stack whenever an algorithm encounters nested structures like matched brackets, tags, or algebraic formulas. Problems demanding undo operations, function execution histories, or evaluating postfix arithmetic require this discipline. It is also the primary structure for monotonic queries where a task asks for the nearest greater or smaller value adjacent to each position in a series.
How to think about it
Picture peeling layers back in exact reverse order of their arrival. Push items as pending jobs or unclosed delimiters encounter the scan. When closing boundaries appear, pop the topmost entry and check for compatibility. For monotonic patterns, maintain an invariant where elements on the stack remain strictly increasing or decreasing; pop any items that violate this rule before recording candidate answers and pushing the current item.
What each operation costs
| Operation | Time |
|---|---|
| push item onto the top | O(1) |
| pop item from the top | O(1) |
| inspect the topmost element | O(1) |
What usually goes wrong
- Popping from or peeking into an empty stack without first verifying that the size is positive, causing runtime null pointer or empty collection errors.
- Forgetting to verify that the stack is completely empty at the end of bracket matching, which mistakenly accepts strings with dangling unclosed opening symbols.
- Storing values instead of indices in monotonic stacks, making it impossible to calculate distance intervals between matching elements afterwards.
Every Stack problem, easiest first
- Valid ParenthesesEasy
- Next Greater Element IEasy
- Min StackMedium
- Evaluate Reverse Polish NotationMedium
- Generate ParenthesesMedium
- Daily TemperaturesMedium
- Car FleetMedium
- Next Greater Element IIMedium
- Decode StringMedium
- Stock Span ProblemMedium
- Asteroid CollisionMedium
- Sum of Subarray MinimumsMedium
- Remove K DigitsMedium
- Largest Rectangle in HistogramHard
- Largest Rectangle in Histogram (Stack)Hard
- Maximal RectangleHard
Roles that need Stack
If you are targeting one of these, Stack sits early in your path rather than being optional.
Track Stack in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks. Free.
Start freeStack interview questions, answered
How many Stack problems should I solve for interviews?
16 curated Stack problems cover the patterns interviews repeat: 2 easy, 11 medium and 3 hard. They are drawn from 3 widely used sheets, deduplicated, and ordered easiest first.
Is Stack actually asked in coding interviews?
Yes, though how much depends on the role. Stack is a core topic for 8 of the 29 engineering roles tracked here, including SDE / Backend Engineer, Full-Stack Developer, Android Developer. For other roles it is lower frequency and belongs later in a study plan.
Which Stack problem should I start with?
Start with Valid Parentheses (Easy). The list on this page is ordered easiest first for that reason, so working top to bottom builds the pattern before the harder variations arrive.
Other topics
Problem set and role mapping as of .