LeetCode
LeetCode 4045: Count Robot Groups
·3 mins
LeetCode
Medium
Stack
Monotonic-Stack
Greedy
LeetCode 4045 note: merge robots already close at t = 0, then go right to left like car fleets, where anything faster than the fleet ahead eventually joins it
LeetCode 3313: Find the Last Marked Nodes in Tree
·2 mins
LeetCode
Hard
Tree
Bfs
Graph
Tree-Diameter
LeetCode 3313 note: the last marked node is the farthest one, and a farthest node can always be a diameter endpoint
LeetCode 2608: Shortest Cycle in a Graph
·3 mins
LeetCode
Hard
Bfs
Graph
LeetCode 2608 note: BFS from every node; a visited neighbor that is not the parent closes a cycle of length dist[u] + dist[v] + 1
LeetCode 2561: Rearranging Fruits
·2 mins
LeetCode
Hard
Greedy
Hash-Table
Sorting
LeetCode 2561 note: every value’s total must be even; sort the excess, and each cheap half item swaps with an expensive one at min(its value, 2 × global minimum)
LeetCode 716: Max Stack
·3 mins
LeetCode
Hard
Stack
Heap
Design
Lazy-Deletion
LeetCode 716 note: store unique ids on both the stack and the heap, record deletions by id, and discard deleted entries lazily; tracking values cannot tell duplicates apart
LeetCode 622: Design Circular Queue
·2 mins
LeetCode
Medium
Queue
Design
Array
LeetCode 622 note: a fixed array plus head and count, every position taken modulo the capacity, and count deciding empty versus full
LeetCode 2218: Maximum Value of K Coins From Piles
·2 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
Prefix-Sum
Array
LeetCode 2218 note: piles are taken from the top, so taking x coins is worth a prefix sum; a grouped knapsack with dp[j] = the best value taking j coins so far, enumerating how many from each pile
LeetCode 4019: Merge Close Characters II
·2 mins
LeetCode
Medium
Hash-Table
String
LeetCode 4019 note: kept characters never change again, so record each character’s last position in the result; a new character within k of it gets merged away
LeetCode 2416: Sum of Prefix Scores of Strings
·2 mins
LeetCode
Hard
Trie
String
Counting
LeetCode 2416 note: each Trie node counts the words passing through it, and a word’s answer is the sum of counts along its path
LeetCode 987: Vertical Order Traversal of a Binary Tree
·2 mins
LeetCode
Hard
Tree
Binary-Tree
Bfs
Sorting
LeetCode 987 note: collect (col, row, val) triples, sort them, and group by column
LeetCode 940: Distinct Subsequences II
·2 mins
LeetCode
Hard
Dynamic-Programming
String
LeetCode 940 note: group by last character; distinct subsequences ending with c = every current distinct subsequence with c appended, plus c itself, replacing the old value
LeetCode 2973: Find Number of Coins to Place in Tree Nodes
·3 mins
LeetCode
Hard
Dynamic-Programming
Tree-Dp
Depth-First-Search
Sorting
Heap
Tree
LeetCode 2973 note: the max product of three is either the three largest or the two smallest times the largest, so each subtree returns only its 2 smallest and 3 largest values, merged in post-order