Monotonic Stack LeetCode Problems: All 58,
With Python Solutions

Every problem in this library that LeetCode tags Monotonic Stack. 47 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
2
Medium
35
Hard
21
1 pattern

How Monotonic Stack problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Monotonic Stack problems — each one explains the approach, gives a Python template and states its complexity.

Eyes only

When the Monotonic Stack problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Monotonic Stack problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (2)

Easy problems
No.Problem
0496Next Greater Element I
1475Final Prices With a Special Discount in a Shop

Medium (35)

Medium problems
No.Problem
0316Remove Duplicate Letters
0402Remove K Digits
0456132 Pattern
0503Next Greater Element II
0581Shortest Unsorted Continuous Subarray
0654Maximum Binary Tree
0739Daily Temperatures
0769Max Chunks To Make Sorted
0853Car Fleet
0901Online Stock Span
0907Sum of Subarray Minimums
0962Maximum Width Ramp
1008Construct Binary Search Tree from Preorder Traversal
1019Next Greater Node In Linked List
1081Smallest Subsequence of Distinct Characters
1124Longest Well-Performing Interval
1130Minimum Cost Tree From Leaf Values
1504Count Submatrices With All Ones
1574Shortest Subarray to be Removed to Make Array Sorted
1673Find the Most Competitive Subsequence
1856Maximum Subarray Min-Product
1996The Number of Weak Characters in the Game
2104Sum of Subarray Ranges
2289Steps to Make Array Non-decreasing
2487Remove Nodes From Linked List
2865Beautiful Towers I
2866Beautiful Towers II
0255Verify Preorder Sequence in Binary Search TreePremium
1762Buildings With an Ocean ViewPremium
1950Maximum of Minimum Values in All SubarraysPremium
2282Number of People That Can Be Seen in a GridPremium
2297Jump Game VIIIPremium
2345Finding the Number of Visible MountainsPremium
2832Maximal Range That Each Element Is Maximum in ItPremium
2863Maximum Length of Semi-Decreasing SubarraysPremium

Hard (21)

Hard problems
No.Problem
0042Trapping Rain Water
0084Largest Rectangle in Histogram
0085Maximal Rectangle
0321Create Maximum Number
0768Max Chunks To Make Sorted II
0975Odd Even Jump
1526Minimum Number of Increments on Subarrays to Form a Target Array
1776Car Fleet II
1793Maximum Score of a Good Subarray
1944Number of Visible People in a Queue
2281Sum of Total Strength of Wizards
2334Subarray With Elements Greater Than Varying Threshold
2454Next Greater Element IV
2617Minimum Number of Visited Cells in a Grid
2736Maximum Sum Queries
2818Apply Operations to Maximize Score
2940Find Building Where Alice and Bob Can Meet
2945Find Maximum Non-decreasing Array Length
1063Number of Valid SubarraysPremium
2030Smallest K-Length Subsequence With Occurrences of a Letter
2355Maximum Number of Books You Can TakePremium