Monotonic Stack Problems
Master monotonic stack problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 43 problems in this category.
Total Problems: 43
Easy: 2
Medium: 24
Hard: 17
Showing 43 of 43 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Monotonic Stack LeetCode Problems List
- 42. Trapping Rain Water - Hard - Monotonic StackGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.... Topics: Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack
- 496. Next Greater Element I - Easy - Monotonic StackThe next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two dis... Topics: Array, Hash Table, Stack, Monotonic Stack
- 883. Car Fleet - Medium - Monotonic StackThere are n cars at given miles away from the starting mile 0, traveling to reach the mile target. You are given two integer arrays position and speed... Topics: Array, Stack, Sorting, Monotonic Stack
- 1570. Final Prices With a Special Discount in a Shop - Easy - Monotonic StackYou are given an integer array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop. If yo... Topics: Array, Stack, Monotonic Stack
- 456. 132 Pattern - Medium - Monotonic StackGiven an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < num... Topics: Array, Binary Search, Stack, Monotonic Stack, Ordered Set
- 503. Next Greater Element II - Medium - Monotonic StackGiven a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in ... Topics: Array, Stack, Monotonic Stack
- 937. Online Stock Span - Medium - Monotonic StackDesign an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span of the st... Topics: Stack, Design, Monotonic Stack, Data Stream
- 316. Remove Duplicate Letters - Medium - Monotonic StackGiven a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicogr... Topics: String, Stack, Greedy, Monotonic Stack
- 84. Largest Rectangle in Histogram - Hard - Monotonic StackGiven an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle ... Topics: Array, Stack, Monotonic Stack
- 581. Shortest Unsorted Continuous Subarray - Medium - Monotonic StackGiven an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole... Topics: Array, Two Pointers, Stack, Greedy, Sorting, Monotonic Stack
- 321. Create Maximum Number - Hard - Monotonic StackYou are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also gi... Topics: Array, Two Pointers, Stack, Greedy, Monotonic Stack
- 1050. Construct Binary Search Tree from Preorder Traversal - Medium - Monotonic StackGiven an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its ro... Topics: Array, Stack, Tree, Binary Search Tree, Monotonic Stack, Binary Tree
- 739. Daily Temperatures - Medium - Monotonic StackGiven an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have t... Topics: Array, Stack, Monotonic Stack
- 3114. Beautiful Towers I - Medium - Monotonic StackYou are given an array heights of n integers representing the number of bricks in n consecutive towers. Your task is to remove some bricks to form a m... Topics: Array, Stack, Monotonic Stack
- 3113. Beautiful Towers II - Medium - Monotonic StackYou are given a 0-indexed array maxHeights of n integers. You are tasked with building n towers in the coordinate line. The ith tower is built at coor... Topics: Array, Stack, Monotonic Stack
- 1902. Car Fleet II - Hard - Monotonic StackThere are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [... Topics: Array, Math, Stack, Heap (Priority Queue), Monotonic Stack
- 2227. Sum of Subarray Ranges - Medium - Monotonic StackYou are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray. Retur... Topics: Array, Stack, Monotonic Stack
- 1305. Number of Visible People in a Queue - Hard - Monotonic StackThere are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers ... Topics: Array, Stack, Monotonic Stack
- 943. Sum of Subarray Minimums - Medium - Monotonic StackGiven an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return ... Topics: Array, Dynamic Programming, Stack, Monotonic Stack
- 402. Remove K Digits - Medium - Monotonic StackGiven string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.... Topics: String, Stack, Greedy, Monotonic Stack
- 3181. Find Building Where Alice and Bob Can Meet - Hard - Monotonic StackYou are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building. If a person is in building i... Topics: Array, Binary Search, Stack, Binary Indexed Tree, Segment Tree, Heap (Priority Queue), Monotonic Stack
- 1628. Count Submatrices With All Ones - Medium - Monotonic StackGiven an m x n binary matrix mat, return the number of submatrices that have all ones.... Topics: Array, Dynamic Programming, Stack, Matrix, Monotonic Stack
- 2368. Sum of Total Strength of Wizards - Hard - Monotonic StackAs the ruler of a kingdom, you have an army of wizards at your command. You are given a 0-indexed integer array strength, where strength[i] denotes th... Topics: Array, Stack, Monotonic Stack, Prefix Sum
- 1985. Maximum Subarray Min-Product - Medium - Monotonic StackThe min-product of an array is equal to the minimum value in the array multiplied by the array's sum. For example, the array [3,2,5] (minimum value is... Topics: Array, Stack, Monotonic Stack, Prefix Sum
- 2123. The Number of Weak Characters in the Game - Medium - Monotonic StackYou are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D i... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 85. Maximal Rectangle - Hard - Monotonic StackGiven a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.... Topics: Array, Dynamic Programming, Stack, Matrix, Monotonic Stack
- 2573. Remove Nodes From Linked List - Medium - Monotonic StackYou are given the head of a linked list. Remove every node which has a node with a greater value anywhere to the right side of it. Return the head of ... Topics: Linked List, Stack, Recursion, Monotonic Stack
- 1633. Minimum Number of Increments on Subarrays to Form a Target Array - Hard - Monotonic StackYou are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operatio... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 654. Maximum Binary Tree - Medium - Monotonic StackYou are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm: Create... Topics: Array, Divide and Conquer, Stack, Tree, Monotonic Stack, Binary Tree
- 3382. Find the Number of Subarrays Where Boundary Elements Are Maximum - Hard - Monotonic StackYou are given an array of positive integers nums. Return the number of subarrays of nums, where the first and the last elements of the subarray are eq... Topics: Array, Binary Search, Stack, Monotonic Stack
- 1017. Odd Even Jump - Hard - Monotonic StackYou are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called ... Topics: Array, Dynamic Programming, Stack, Sorting, Monotonic Stack, Ordered Set
- 2419. Subarray With Elements Greater Than Varying Threshold - Hard - Monotonic StackYou are given an integer array nums and an integer threshold. Find any subarray of nums of length k such that every element in the subarray is greater... Topics: Array, Stack, Union Find, Monotonic Stack
- 1918. Maximum Score of a Good Subarray - Hard - Monotonic StackYou are given an array of integers nums (0-indexed) and an integer k. The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j... Topics: Array, Two Pointers, Binary Search, Stack, Monotonic Stack
- 1072. Next Greater Node In Linked List - Medium - Monotonic StackYou are given the head of a linked list with n nodes. For each node in the list, find the value of the next greater node. That is, for each node, find... Topics: Array, Linked List, Stack, Monotonic Stack
- 3725. Maximum and Minimum Sums of at Most Size K Subarrays - Hard - Monotonic StackYou are given an integer array nums and a positive integer k. Return the sum of the maximum and minimum elements of all subarrays with at most k eleme... Topics: Array, Math, Stack, Monotonic Stack
- 779. Max Chunks To Make Sorted II - Hard - Monotonic StackYou are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating ... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 780. Max Chunks To Make Sorted - Medium - Monotonic StackYou are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 3954. Maximum Balanced Shipments - Medium - Monotonic StackYou are given an integer array weight of length n, representing the weights of n parcels arranged in a straight line. A shipment is defined as a conti... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 1002. Maximum Width Ramp - Medium - Monotonic StackA ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i. Given an integer array num... Topics: Array, Two Pointers, Stack, Monotonic Stack
- 1228. Minimum Cost Tree From Leaf Values - Medium - Monotonic StackGiven an array arr of positive integers, consider all binary trees such that: Each node has either 0 or 2 children; The values of arr correspond to th... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 2549. Next Greater Element IV - Hard - Monotonic StackYou are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer. The seco... Topics: Array, Binary Search, Stack, Sorting, Heap (Priority Queue), Monotonic Stack
- 1159. Smallest Subsequence of Distinct Characters - Medium - Monotonic StackGiven a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.... Topics: String, Stack, Greedy, Monotonic Stack
- 2157. Smallest K-Length Subsequence With Occurrences of a Letter - Hard - Monotonic StackYou are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length k... Topics: String, Stack, Greedy, Monotonic Stack
Related LeetCode Topics
- Array LeetCode Problems
- Backtracking LeetCode Problems
- Biconnected Component LeetCode Problems
- Binary Indexed Tree LeetCode Problems
- Binary Search LeetCode Problems
- Binary Search Tree LeetCode Problems
- Binary Tree LeetCode Problems
- Bit Manipulation LeetCode Problems
- Bitmask LeetCode Problems
- Brainteaser LeetCode Problems
- Breadth-First Search LeetCode Problems
- Bucket Sort LeetCode Problems
- Combinatorics LeetCode Problems
- Concurrency LeetCode Problems
- Counting LeetCode Problems
- Counting Sort LeetCode Problems
- Data Stream LeetCode Problems
- Database LeetCode Problems
- Depth-First Search LeetCode Problems
- Design LeetCode Problems