When to use it
Reach for Histogram rectangle when a stack & monotonic stack problem matches the cues in this lesson — especially after you’ve ruled out a brute-force nested scan.
Pattern
Histogram rectangle is a reusable approach under Stack & Monotonic Stack. Once you recognize the shape of the input and the ask, this pattern gives you a standard plan instead of inventing a new algorithm from scratch.
Reach for Histogram rectangle when a stack & monotonic stack problem matches the cues in this lesson — especially after you’ve ruled out a brute-force nested scan.
Reference implementation in C#, Python, Java, JavaScript, and C++.
Interviewers grade pattern recognition. Naming Histogram rectangle early shows you can classify the problem inside Linear DS.
Drill Histogram rectangle with Stack & Monotonic Stack problems — filter the bank and solve 2–3 Easy/Medium items while saying the invariant out loud.
Related Stack & Monotonic Stack problems — open any one and apply Histogram rectangle.
Valid Parentheses
Stack
Longest Valid Parentheses
Stack / DP
Trapping Rain Water
Two Pointers
Largest Rectangle in Histogram
Monotonic Stack
Maximal Rectangle
Stack / DP
Binary Tree Inorder Traversal
Tree
Min Stack
Design
Decode String
Stack
Valid Parenthesis String
Greedy