Monotonic Stack Problems for Coding Interviews
15 Monotonic Stack problems from real coding interviews, each with test cases you can run online. By difficulty they split into 1 basic, 9 intermediate and 5 advanced. The companies that ask them most often are Amazon, Bloomberg, Google, Microsoft.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Trapping Rain Water (Advanced)
- Largest Rectangle in Histogram (Advanced)
- Next Greater Value (Intermediate)
- Daily Temperatures (Intermediate)
- Remove K Digits to Get the Smallest Number (Intermediate)
- Circular Next Greater Value (Intermediate)
- Largest All-Ones Rectangle (Intermediate)
- Maximum Rectangle in Histogram (Advanced)
- Next Greater Node in Linked List (Intermediate)
- Number of Visible People in a Queue (Advanced)
- Trapping Rain Water II (Advanced)
- Next Greater Element Distance Sum (Intermediate)
- Stock Span Total (Basic)
- Stern-Brocot Path of Fraction (Intermediate)
- Next Greater Element Queries (Intermediate)
Related
Frequently asked questions
How do I get good at monotonic stack problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run monotonic stack problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.