Pattern
Stack
A compact view of archive entries grouped by recurring technique.
52 entries
52 entries tagged as Stack.
01.04.2026
hard2751. Robot Collisions
Collide LR robots
11.01.2026
hard85. Maximal Rectangle
Max all-1 rectangle in 2D matrix stack
10.11.2025
medium3542. Minimum Operations to Convert All Elements to Zero
Min ops to zeros by making min of subarrays 0 stack
23.07.2025
medium1717. Maximum Score From Removing Substrings
Max removals ab=x, ba=y
06.06.2025
medium2434. Using a Robot to Print the Lexicographically Smallest String
Smallest string by writing to stack
29.03.2025
hard2818. Apply Operations to Maximize Score
Multiply k numbers with max prime factor count stack
23.02.2025
medium889. Construct Binary Tree from Preorder and Postorder Traversal
Tree from preorder & postorder
22.02.2025
hard1028. Recover a Tree From Preorder Traversal
Recover binary tree from depth-dashes string
27.12.2024
medium1014. Best Sightseeing Pair
Max (a[i] + a[j] + i - j), i > j
22.12.2024
hard2940. Find Building Where Alice and Bob Can Meet
Common indices t, h[t] > h[a], h[t] > h[b] for queries q[][a,b] stack
18.12.2024
easy1475. Final Prices With a Special Discount in a Shop
Subtract next smaller value stack
13.12.2024
medium2593. Find Score of an Array After Marking All Elements
Sum of minimums in order excluding siblings stack
27.10.2024
medium1277. Count Square Submatrices with All Ones
Count 1-filled squares in 2D matrix programming
20.10.2024
hard1106. Parsing A Boolean Expression
before evaluation, index i should point at the first token of the subproblem
10.10.2024
medium962. Maximum Width Ramp
Max j-i between a[i] <= a[j] in an array stack
09.10.2024
medium921. Minimum Add to Make Parentheses Valid
Minimum inserts to balance brackets
08.10.2024
medium1963. Minimum Number of Swaps to Make the String Balanced
Min swaps to balance brackets pointers
07.10.2024
easy2696. Minimum String Length After Removing Substrings
Remove 'AB' and 'CD' from the string
30.09.2024
medium1381. Design a Stack With Increment Operation
Stack with range increment operation
14.07.2024
hard726. Number of Atoms
Simplify chemical formula parenthesis
13.07.2024
hard2751. Robot Collisions
D dimensional robots fight
12.07.2024
medium1717. Maximum Score From Removing Substrings
Max score removing from s, x for ab, y for ba
12.05.2024
easy2373. Largest Local Values in a Matrix
Max pooling by 3x3 matrix
06.05.2024
medium2487. Remove Nodes From Linked List
Make a Linked List non-increasing list
13.04.2024
hard85. Maximal Rectangle
Max 1-only area in a 0-1 matrix
12.04.2024
hard42. Trapping Rain Water
Trap the water in area between vertical walls
11.04.2024
medium402. Remove K Digits
Minimum number after removing k digits
06.04.2024
medium1249. Minimum Remove to Make Valid Parentheses
Remove minimum to make parenthesis valid
05.04.2024
easy1544. Make The String Great
Remove lowercase-uppercase pairs
31.01.2024
medium739. Daily Temperatures
Array of distances to the next largest.
30.01.2024
medium150. Evaluate Reverse Polish Notation
Solve Reverse Polish Notation.
20.01.2024
medium907. Sum of Subarray Minimums
Sum of minimums of all array ranges.
20.10.2023
medium341. Flatten Nested List Iterator
Implement graph iterator
19.10.2023
medium844. Backspace String Compare
Remove all of the backspaced chars before comparing
30.09.2023
medium456. 132 Pattern
132 pattern in array
28.08.2023
easy225. Implement Stack using Queues
Create a Stack using Queue's push/pop methods.
20.07.2023
medium735. Asteroid Collision
Result after asteroids collide left-right exploding by size: 15 5 -15 -5 5 -> -15 -5 5
17.07.2023
medium445. Add Two Numbers II
Linked List of sum of two Linked Lists numbers, 9->9 + 1 = 1->0->0
17.05.2023
medium2130. Maximum Twin Sum of a Linked List
Max sum of head-tail twin ListNodes: a-b-c-d -> max(a+d, b+c)
13.04.2023
medium946. Validate Stack Sequences
use one iteration and a second pointer for pop
12.04.2023
medium71. Simplify Path
split the string by /
11.04.2023
medium2390. Removing Stars From a String
we can use a Stack, or just StringBuilder
10.04.2023
medium20. Valid Parentheses
use HashMap to check matching bracket.
13.03.2023
easy101. Symmetric Tree
Recursive: just write helper function.
8.02.2023
medium45. Jump Game II
use stack to store jumps
10.01.2023
easy100. Same Tree
fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean = p == null && q == null ||
18.12.2022
medium739. Daily Temperatures
fun dailyTemperatures(temperatures: IntArray): IntArray {
17.12.2022
medium150. Evaluate Reverse Polish Notation
fun evalRPN(tokens: Array
16.12.2022
easy232. Implement Queue using Stacks
class MyQueue() {
13.11.2022
mediumReverse Words In A String
A simple trick: reverse all the string, then reverse each word.
10.11.2022
easyRemove All Adjacent Duplicates In String
Just scan symbols one by one and remove duplicates from the end.
9.11.2022
mediumOnline Stock Span
So, we need to keep increasing sequence of numbers, increasing/decreasing stack will help.