Top 50 Must-Do LeetCode Questions on Stacks for Your Coding Interview Preparation
In this article, I have compiled a list of the top 50 LeetCode questions focused on Stacks, a fundamental data structure that you’ll encounter frequently in coding interviews. These problems are categorized into Easy, Medium, and Hard difficulty levels, ensuring comprehensive coverage of the topic.
Easy Questions (20 Questions)
Valid Parentheses (20)
Check if a string of brackets is valid, meaning every open bracket has a corresponding close bracket in the correct order.Min Stack (155)
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement Stack using Queues (225)
Use one or two queues to implement a stack with standard stack operations.Baseball Game (682)
Simulate a baseball game where valid operations include adding scores or removing the last added score.Next Greater Element I (496)
Find the next greater element for each number in an array by leveraging a stack for efficiency.Remove All Adjacent Duplicates in String (1047)
Remove all adjacent duplicate letters from a string until no more adjacent duplicates exist.Implement Queue using Stacks (232)
Use two stacks to implement a queue with standard queue operations.Daily Temperatures (739)
For each day, find out how many days you’d have to wait for a warmer temperature.Final Prices With a Special Discount (1475)
Calculate final prices of items considering discounts based on their next smaller element.Backspace String Compare (844)
Compare two strings considering backspace (#
) characters and their effects.Check If Word Is Valid After Substitutions (1003)
Validate if a string can be reduced to an empty string by repeatedly removing "abc".Remove Outermost Parentheses (1021)
Remove the outermost parentheses of a valid parentheses string.Sort Array by Increasing Frequency (1636)
Sort an array by the frequency of elements and use stacks for auxiliary operations.Next Greater Node In Linked List (1019)
Find the next greater node value for every node in a linked list using stacks.Reverse Substrings Between Each Pair of Parentheses (1190)
Reverse substrings enclosed in parentheses in a string.Decode String (394)
Decode a string encoded with patterns like "3[a2[c]]" using a stack.Longest Valid Parentheses (32)
Find the length of the longest valid parentheses substring.Evaluate Reverse Polish Notation (150)
Evaluate an expression in Reverse Polish Notation (RPN) using a stack.Find the Winner of the Circular Game (1823)
Simulate a circular game using stacks to eliminate players and find the winner.Check If a Parentheses String Can Be Valid (2116)
Determine if a string with*
and()
can be a valid parentheses sequence.
Medium Questions (25 Questions)
Next Greater Element II (503)
Find the next greater element for each number in a circular array.Score of Parentheses (856)
Compute the score of a balanced parentheses string using stacks.132 Pattern (456)
Check if there is a 132 pattern in an array using a stack.Car Fleet (853)
Determine the number of car fleets that arrive at the destination.Asteroid Collision (735)
Simulate the collision of asteroids moving in opposite directions.Exclusive Time of Functions (636)
Calculate the exclusive time of each function from a sequence of logs.Remove K Digits (402)
Removek
digits from a number to form the smallest number possible.Maximum Frequency Stack (895)
Design a stack that returns the most frequently added element.Simplify Path (71)
Simplify an absolute file path in Unix-like file systems.Online Stock Span (901)
Calculate the stock span for a given stock's price on a series of days.Minimum Remove to Make Valid Parentheses (1249)
Remove the minimum number of invalid parentheses to make the string valid.Largest Rectangle in Histogram (84)
Find the largest rectangle area in a histogram.Basic Calculator II (227)
Evaluate a mathematical expression string with+
,-
,*
,/
.Trapping Rain Water (42)
Calculate how much water can be trapped between bars of varying heights.Find the Most Competitive Subsequence (1673)
Find the smallest subsequence ofk
elements from the array in the same order.Maximum Width Ramp (962)
Find the maximum width ramp between indices such that values decrease.Validate Stack Sequences (946)
Check if a sequence of pushed and popped integers is valid.Expression Add Operators (282)
Add operators (+
,-
,*
) between digits to evaluate to a target.Design Browser History (1472)
Simulate browser navigation using stacks for back and forward actions.Sum of Subarray Minimums (907)
Calculate the sum of the minimum values of all subarrays.Basic Calculator (224)
Evaluate a basic mathematical expression string with+
,-
, and parentheses.Remove Duplicate Letters (316)
Remove duplicate letters to form the smallest lexicographical string.The Earliest Moment When Everyone Become Friends (1101)
Use stacks to determine the earliest time a group becomes fully connected.Clone a Stack Without Affecting the Original
Clone a stack recursively or iteratively without altering its contents.Redundant Connection (684)
Find the redundant edge that, when removed, leaves a tree.
Hard Questions (5 Questions)
Expression Add Operators (282)
Form expressions with operators (+
,-
,*
) to evaluate to a target number.Basic Calculator III (772)
Evaluate a mathematical expression string with+
,-
,*
,/
, and parentheses.Maximum Rectangle (85)
Find the maximal rectangle of1s
in a binary matrix.Minimize Deviation in Array (1675)
Minimize the maximum difference between any two elements in the array.Remove Invalid Parentheses (301)
Remove the minimum number of invalid parentheses to make all strings valid.
By practicing these questions, you will build a strong foundation in Stacks and enhance your problem-solving skills for technical interviews. Which one are you starting with today?
Top comments (0)