Stack

Level: Intermediate

1. Design a Max Stack: Design a stack that supports push, pop, top, peekMax, and popMax operations.
2. Evaluate Infix Expression: Implement a function to evaluate an infix expression using a stack.
3. Expression Tree: Write a function to construct an expression tree from a postfix expression using a stack.
4. Remove K Digits: Implement a function to remove k digits from a number to get the smallest possible number using a stack.
5. Longest Valid Parentheses: Write a function to find the length of the longest valid parentheses substring using a stack.
6. Trapping Rain Water: Implement a function to solve the trapping rain water problem using a stack.
7. Maximal Rectangle: Write a function to find the maximal rectangle in a binary matrix using a stack.
8. Score of Parentheses: Implement a function to calculate the score of parentheses using a stack.
9. Basic Calculator II: Write a function to implement a basic calculator that can evaluate expressions with +, -, *, and / using a stack.
10. 132 Pattern: Implement a function to find the 132 pattern in an array using a stack.
11. Validate Stack Sequences: Write a function to validate if two sequences are stack push and pop sequences.
12. Remove All Adjacent Duplicates: Implement a function to remove all adjacent duplicates in a string using a stack.
13. Largest Rectangle in Skyline: Write a function to find the largest rectangle in the skyline using a stack.
14. Simplify Path: Implement a function to simplify a Unix-style file path using a stack.
15. Remove K Digits to Form Minimum Number: Write a function to remove k digits to form the minimum possible number using a stack.
16. Basic Calculator III: Implement a function to evaluate expressions with parentheses and basic arithmetic using a stack.
17. Validate Bracket Expressions: Write a function to validate expressions containing different types of brackets using a stack.
18. Maximal Rectangle Area: Implement a function to find the maximal rectangle area in a binary matrix using a stack.
19. Remove Duplicate Letters: Write a function to remove duplicate letters from a string using a stack.
20. Design a Min Stack with Constant Space: Design a stack that supports retrieving the minimum element in constant space.
21. Find 132 Pattern: Implement a function to find the 132 pattern in a list using a stack.
22. Asteroid Collision: Write a function to simulate asteroid collisions using a stack.
23. Decode At Index: Implement a function to decode a string at a given index using a stack.
24. Make The String Great: Write a function to make a string great by removing pairs of adjacent characters using a stack.
25. Online Stock Span: Implement a class that calculates the stock span using a stack.
26. Simplify Path II: Write a function to simplify a Unix-style file path using a stack.
27. Reverse Substrings Between Parentheses: Implement a function to reverse substrings between each pair of matching parentheses using a stack.
28. Validate Stack Operations: Write a function to validate the sequences of stack operations.
29. Largest Area in Binary Matrix: Implement a function to find the largest area of rectangles in a binary matrix using a stack.
30. Find the Most Competitive Subsequence: Write a function to find the most competitive subsequence of a given length using a stack.

Beginner Level: View

Advanced Level: View