monotonic stack
monotonic stack is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
Pattern Bridge
High-Pressure Round
Trapping Rain Water
Calculate the total trapped rain water using the elevation map array, leveraging dynamic programming and two-pointer pat…
Largest Rectangle in Histogram
Find the maximal rectangular area in a histogram using stack-based state management for precise bar tracking and width c…
Maximal Rectangle
Compute the largest rectangle of 1's in a binary matrix using dynamic programming and stack-based state transitions effi…
Remove Duplicate Letters
Remove duplicate letters from a string to produce the lexicographically smallest result using stack-based state manageme…
Create Maximum Number
Create Maximum Number involves merging digits from two arrays while preserving order, maximizing the resulting number.
Remove K Digits
Remove K Digits requires selecting which digits to drop using a monotonic stack for the smallest possible integer result…
132 Pattern
Identify whether a given integer array contains a 132 pattern subsequence using efficient stack and search techniques.
Next Greater Element I
Find the next greater element for each number in nums1 from the nums2 array using an optimized approach.
Next Greater Element II
Solve the Next Greater Element II problem by using a stack-based state management approach for circular arrays.
Shortest Unsorted Continuous Subarray
Find the shortest unsorted continuous subarray that, if sorted, would sort the entire array.
Maximum Binary Tree
Construct a maximum binary tree by recursively selecting the largest element and dividing the array into left and right …
Daily Temperatures
In the Daily Temperatures problem, you need to find out how many days to wait for a warmer temperature based on given da…
Max Chunks To Make Sorted II
Determine the maximum number of chunks you can split an array into so that sorting each chunk results in a fully sorted …
Max Chunks To Make Sorted
The Max Chunks To Make Sorted problem requires you to split an array into the maximum number of chunks that can be sorte…
Car Fleet
The Car Fleet problem asks how many car fleets will reach a target given their starting positions and speeds, considerin…
Online Stock Span
Design an efficient algorithm using stacks to calculate the stock span for daily price quotes.
Sum of Subarray Minimums
Calculate the sum of minimum values across all subarrays of a given array modulo 10^9 + 7.
Maximum Width Ramp
Find the maximum width of a ramp where nums[i] <= nums[j] for i < j using a two-pointer approach.
Odd Even Jump
Determine the number of valid starting indices in an array where you can reach the end with alternating odd and even jum…
Construct Binary Search Tree from Preorder Traversal
Construct a binary search tree directly from a preorder traversal array using stack-based state tracking efficiently.
Next Greater Node In Linked List
Find the next greater value for each node in a linked list using monotonic stack techniques for efficient traversal.
Smallest Subsequence of Distinct Characters
The Smallest Subsequence of Distinct Characters problem asks you to find the lexicographically smallest subsequence of a…
Longest Well-Performing Interval
The Longest Well-Performing Interval problem challenges you to find the longest subarray where tiring days exceed non-ti…
Minimum Cost Tree From Leaf Values
Compute the minimum sum of non-leaf nodes in a binary tree formed from array leaves using dynamic programming efficientl…
Final Prices With a Special Discount in a Shop
Calculate final prices with discounts applied in a shop using a stack-based state management approach to find the correc…
Count Submatrices With All Ones
Count Submatrices With All Ones is a dynamic programming problem focusing on submatrix counting using an efficient row-b…
Minimum Number of Increments on Subarrays to Form a Target Array
The problem asks for the minimum number of operations to transform an initial array of zeros into a target array using s…
Shortest Subarray to be Removed to Make Array Sorted
Find the shortest subarray to remove in order to make an array non-decreasing using binary search and two-pointer techni…
Find the Most Competitive Subsequence
Identify the lexicographically smallest subsequence of size k using stack-based greedy selection in array traversal.
Car Fleet II
Car Fleet II involves calculating collision times between cars traveling at different speeds along a one-lane road using…
Maximum Score of a Good Subarray
Maximize the score of a good subarray using binary search to explore the valid answer space with a focus on two-pointer …
Maximum Subarray Min-Product
The problem asks to find the maximum min-product of any non-empty subarray of nums.
Number of Visible People in a Queue
Compute how many people each person in a queue can see to their right using efficient stack-based state management.
The Number of Weak Characters in the Game
Identify all weak characters in a game by analyzing attack and defense values using a stack-based greedy sorting approac…
Smallest K-Length Subsequence With Occurrences of a Letter
Find the lexicographically smallest subsequence of length k with at least repetition occurrences of a given letter using…
Sum of Subarray Ranges
Compute the total sum of ranges for all contiguous subarrays efficiently using stack-based state management techniques.
Sum of Total Strength of Wizards
The Sum of Total Strength of Wizards problem asks for the sum of the total strengths of all contiguous subarrays of wiza…
Steps to Make Array Non-decreasing
Determine the minimum steps to make an array non-decreasing using linked-list pointer manipulation and monotonic stack t…
Subarray With Elements Greater Than Varying Threshold
Find the size of a subarray with all elements greater than threshold divided by length using stack-based state managemen…
Next Greater Element IV
Find the second greater integer for each element in an array using binary search and monotonic stack techniques.
Remove Nodes From Linked List
This problem requires removing nodes from a linked list when a larger node exists to their right, testing pointer manipu…
Minimum Number of Visited Cells in a Grid
Determine the minimum number of cells to visit in a grid using state transition dynamic programming and efficient traver…
Maximum Sum Queries
Find the maximum sum of paired elements from two arrays under query constraints using efficient binary search techniques…
Apply Operations to Maximize Score
Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.
Beautiful Towers I
Solve Beautiful Towers I by testing each peak and enforcing mountain limits with monotonic stack style height propagatio…
Beautiful Towers II
Maximize tower configurations with the stack-based approach while ensuring mountain-like patterns in this medium difficu…
Find Building Where Alice and Bob Can Meet
Determine the leftmost building where Alice and Bob can meet using a binary search over valid move sequences.
Find Maximum Non-decreasing Array Length
Solve Find Maximum Non-decreasing Array Length with prefix-sum DP transitions that maximize kept segments while preservi…
Find the Number of Subarrays Where Boundary Elements Are Maximum
Count the subarrays where the first and last elements are the largest in the subarray, utilizing binary search over vali…
Minimum Operations to Make Array Equal to Target
This problem requires calculating the minimum number of operations to transform one array into another using state trans…
Count Non-Decreasing Subarrays After K Operations
This problem asks you to count non-decreasing subarrays in a given array after applying at most k operations.
Maximum and Minimum Sums of at Most Size K Subarrays
Compute the sum of maximum and minimum values in all subarrays up to size k using efficient stack-based state management…
Make Array Non-decreasing
Determine the maximum size of a non-decreasing array by replacing subarrays with their maximum values efficiently.
Minimum Operations to Convert All Elements to Zero
Calculate the fewest operations to turn all numbers in an array to zero using subarray minimum elimination strategy.
Related Patterns
Stack-based state management
25 linked problems
State transition dynamic programming
10 linked problems
Binary search over the valid answer space
7 linked problems
Two-pointer scanning with invariant tracking
3 linked problems
Array scanning plus hash lookup
3 linked problems
Linked-list pointer manipulation
3 linked problems