stack
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
Valid Parentheses
Determine if a string of parentheses, brackets, and braces is correctly nested using a stack for proper order validation…
Longest Valid Parentheses
Compute the length of the longest well-formed parentheses substring using state transition dynamic programming and stack…
Trapping Rain Water
Calculate the total trapped rain water using the elevation map array, leveraging dynamic programming and two-pointer pat…
Simplify Path
Simplify a Unix-style path by transforming it into its canonical form using stack-based state management.
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…
Binary Tree Inorder Traversal
Binary Tree Inorder Traversal asks you to visit left subtree, node, then right subtree without losing position while mov…
Flatten Binary Tree to Linked List
Flatten a binary tree into a right-skewed linked list by manipulating pointers following a pre-order traversal, handling…
Reorder List
Reorder List requires careful pointer manipulation in a singly linked list to interleave nodes from the ends without alt…
Binary Tree Preorder Traversal
Perform a binary tree preorder traversal by visiting root nodes first, then left and right subtrees, tracking state iter…
Binary Tree Postorder Traversal
Solve Binary Tree Postorder Traversal using state tracking and binary-tree traversal techniques, focusing on Stack, Tree…
Evaluate Reverse Polish Notation
Compute the result of an arithmetic expression in Reverse Polish Notation using a stack to manage operands efficiently.
Min Stack
Design a stack with O(1) operations to push, pop, retrieve the top element, and get the minimum element in constant time…
Binary Search Tree Iterator
Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…
Basic Calculator
Implement a basic calculator to evaluate mathematical expressions, ensuring correct evaluation with stack-based manageme…
Implement Stack using Queues
This problem tests your ability to simulate a LIFO stack using two queues while preserving all standard stack operations…
Basic Calculator II
Basic Calculator II evaluates a mathematical expression with operators and integers, handling basic arithmetic with prec…
Implement Queue using Stacks
Implement a queue using two stacks, focusing on stack-based state management to achieve FIFO behavior in a queue.
Palindrome Linked List
Solve Palindrome Linked List by finding the midpoint, reversing the second half, and comparing mirrored nodes in linear …
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.
Verify Preorder Serialization of a Binary Tree
Determine if a given string correctly represents a binary tree preorder traversal using state tracking and slot counting…
Flatten Nested List Iterator
Implement an iterator to flatten a nested list of integers, accounting for potential nesting levels.
Mini Parser
Deserialize a nested list string using stack-based state management, handling integers and nested lists with depth-first…
Longest Absolute File Path
Find the length of the longest absolute file path in a filesystem string using stack-based depth tracking efficiently.
Decode String
Decode a nested encoded string using stack-based state management, handling repeated patterns efficiently with recursion…
Remove K Digits
Remove K Digits requires selecting which digits to drop using a monotonic stack for the smallest possible integer result…
Add Two Numbers II
Add Two Numbers II involves summing two numbers represented as linked lists and returning the result as a new linked lis…
132 Pattern
Identify whether a given integer array contains a 132 pattern subsequence using efficient stack and search techniques.
Zuma Game
The Zuma Game involves clearing balls from the board using a limited hand, applying dynamic programming and state transi…
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.
N-ary Tree Preorder Traversal
Solve the N-ary Tree Preorder Traversal problem using depth-first search and stack-based traversal methods.
N-ary Tree Postorder Traversal
Postorder traversal of an N-ary tree can be efficiently solved using DFS and stack-based methods, tracking state across …
Tag Validator
The Tag Validator problem involves validating a code snippet by parsing through tags using a stack-based state managemen…
Exclusive Time of Functions
Solve the 'Exclusive Time of Functions' problem using stack-based state management for accurate function execution time …
Maximum Binary Tree
Construct a maximum binary tree by recursively selecting the largest element and dividing the array into left and right …
Valid Parenthesis String
Solve the Valid Parenthesis String problem by leveraging state transition dynamic programming to handle parentheses and …
Baseball Game
Simulate baseball score operations using a stack-based approach to compute the final score after all operations.
Number of Atoms
Compute the exact count of each atom in a chemical formula using stack-based state management and hashing techniques eff…
Asteroid Collision
Determine the final positions of moving asteroids using a stack-based simulation for efficient collision resolution in l…
Parse Lisp Expression
Parse Lisp expressions using stack-based state management to evaluate variables and operations.
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…
Basic Calculator IV
Simplify mathematical expressions using stack-based state management, handling variables, operators, and polynomial term…
Backspace String Compare
Compare two strings after processing backspaces using efficient two-pointer scanning and careful invariant tracking to e…
Car Fleet
The Car Fleet problem asks how many car fleets will reach a target given their starting positions and speeds, considerin…
Score of Parentheses
Calculate the score of a balanced parentheses string using stack-based state management for an optimal solution.
Decoded String at Index
Decode the string and find the k-th letter efficiently using stack-based state management in this problem.
Maximum Frequency Stack
Design a stack-like data structure to manage elements and handle frequent stack operations, including popping the most f…
Increasing Order Search Tree
Rearrange a binary search tree so all nodes follow increasing order with only right children using in-order traversal.
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.
Minimum Add to Make Parentheses Valid
Compute the minimum insertions needed to make a parentheses string valid using efficient stack-based state tracking tech…
Stamping The Sequence
Solve Stamping The Sequence with stack-based state management to convert string s to target using stamp efficiently.
Validate Stack Sequences
Determine if a sequence of push and pop operations can produce the given popped array using a stack-based state approach…
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…
Check If Word Is Valid After Substitutions
Determine if a string can be built from repeated 'abc' insertions using stack-based state management, verifying sequence…
Clumsy Factorial
Compute the clumsy factorial of a number using a fixed rotation of multiply, divide, add, and subtract operations effici…
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.
Remove Outermost Parentheses
Remove Outermost Parentheses simplifies a valid parentheses string by removing the outermost layers of parentheses in ea…
Remove All Adjacent Duplicates In String
Solve Remove All Adjacent Duplicates In String by simulating deletions with a stack that collapses matching neighbors im…
Smallest Subsequence of Distinct Characters
The Smallest Subsequence of Distinct Characters problem asks you to find the lexicographically smallest subsequence of a…
Brace Expansion II
Solve Brace Expansion II efficiently by using stack-based state management to generate all unique combinations of nested…
Parsing A Boolean Expression
Solve the "Parsing A Boolean Expression" problem by evaluating boolean expressions using stack-based state management, r…
Maximum Nesting Depth of Two Valid Parentheses Strings
This problem challenges you to compute the maximum nesting depth of two valid parentheses strings using stack-based stat…
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…
Dinner Plate Stacks
Design a system that manages dinner plate stacks using stack-based state management, handling dynamic plate placement an…
Reverse Substrings Between Each Pair of Parentheses
Reverse all substrings within matched parentheses using a stack-based approach for efficient state tracking and reversal…
Remove All Adjacent Duplicates in String II
Remove all adjacent duplicates in the string using stack-based state management with a given threshold k.
Minimum Remove to Make Valid Parentheses
Given a string with parentheses and letters, remove the fewest parentheses to produce any valid balanced string efficien…
Design a Stack With Increment Operation
Implement a stack that supports push, pop, and targeted increment operations efficiently using array-based state managem…
Build an Array With Stack Operations
Simulate stack operations to match a target array while processing numbers from 1 to n.
Design Browser History
Implement a browser history tracker with back, forward, and visit operations using linked-list pointer manipulation effi…
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…
Minimum Insertions to Balance a Parentheses String
Compute the minimum insertions to transform a parentheses string into a balanced string using efficient stack tracking.
Make The String Great
This problem requires removing adjacent characters that cancel each other out, leveraging stack-based state management.
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…
Crawler Log Folder
Simulate folder navigation based on a list of operations to determine the current folder depth.
Maximum Nesting Depth of the Parentheses
Find the maximum nesting depth of parentheses in a valid string using stack-based state management.
Minimum Deletions to Make String Balanced
Determine the minimum number of deletions to transform a string of 'a' and 'b' into a balanced order using DP.
Find the Most Competitive Subsequence
Identify the lexicographically smallest subsequence of size k using stack-based greedy selection in array traversal.
Number of Students Unable to Eat Lunch
Simulate a queue of students with sandwich preferences and determine how many can't eat based on available sandwiches.
Maximum Score From Removing Substrings
Compute the highest score by greedily removing specific substrings using a stack to track state transitions efficiently.
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.
Minimum Cost to Change the Final Value of Expression
Determine the minimum operations to change a boolean expression's result using state transition dynamic programming effi…
Remove All Occurrences of a Substring
Remove all occurrences of a specified substring from a string using efficient stack-based state management.
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.
Minimum Number of Swaps to Make the String Balanced
Determine the minimum swaps to balance a bracket string using two-pointer scanning with invariant tracking efficiently.
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…
Reverse Prefix of Word
Reverse the prefix of a string starting from index 0 to the first occurrence of a given character.
The Score of Students Solving Math Expression
Calculate student scores for a single-digit math expression using state transition dynamic programming to track all vali…
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.
Check if a Parentheses String Can Be Valid
Determine if a parentheses string can be transformed into a valid sequence considering locked positions using stack logi…
Maximum Twin Sum of a Linked List
Find the maximum twin sum in a linked list by manipulating pointers efficiently and leveraging stack or reversal techniq…
Replace Non-Coprime Numbers in Array
Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…
Count Collisions on a Road
Count Collisions on a Road is a problem where you calculate the number of car collisions based on their movements in a s…
Minimum Deletions to Make Array Beautiful
Determine the minimum deletions required to transform an array into a beautiful sequence using stack-based state managem…
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…
Design a Text Editor
Design a text editor that supports text manipulation and cursor navigation operations efficiently with linked-list-based…
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…
Construct Smallest Number From DI String
Construct the lexicographically smallest string that fits the increasing and decreasing conditions of a given pattern.
Removing Stars From a String
Remove all stars from a string by simulating the removal process using a stack to manage characters and stars efficientl…
Using a Robot to Print the Lexicographically Smallest String
Solve the problem of using a robot to print the lexicographically smallest string with stack-based state management.
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 Time to Complete All Tasks
Determine the minimum active time for a computer to complete all scheduled tasks within their specific time windows effi…
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…
Minimum Additions to Make Valid String
Determine the minimum insertions required to transform a given string into repeated concatenations of 'abc' using dynami…
Minimum String Length After Removing Substrings
Determine the smallest string length after repeatedly removing AB or CD substrings using stack-based simulation techniqu…
Maximum Sum Queries
Find the maximum sum of paired elements from two arrays under query constraints using efficient binary search techniques…
Robot Collisions
Robot Collisions involves simulating robot movements and handling collisions with stack-based state management.
Maximum Elegance of a K-Length Subsequence
Maximize elegance of a k-length subsequence from a list of items with profits and categories.
Double a Number Represented as a Linked List
Double a number represented as a linked list by carefully managing node values and carries with pointer traversal techni…
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…
Lexicographically Minimum String After Removing Stars
Find the lexicographically smallest string by removing stars using stack-based state management and careful character se…
Clear Digits
Remove all digits from a given string by applying a repeated operation to form the final string without digits.
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…
Find Mirror Score of a String
Calculate the mirror score of a string using stack-based state management for matching letters efficiently and accuratel…
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.
Resulting String After Adjacent Removals
This problem focuses on removing adjacent characters in a string using a stack-based approach until no more operations a…
Related Patterns
Stack-based state management
81 linked problems
State transition dynamic programming
17 linked problems
Binary-tree traversal and state tracking
11 linked problems
Linked-list pointer manipulation
11 linked problems
Binary search over the valid answer space
8 linked problems
Two-pointer scanning with invariant tracking
6 linked problems