LeetCode
LeetCode 499: The Maze III
·3 mins
LeetCode
Hard
Graph
Dijkstra
Shortest-Path
Heap
Matrix
LeetCode 499 note: Dijkstra prioritized by (distance, path string), and the ball stops when it rolls over the hole
LeetCode 864: Shortest Path to Get All Keys
·3 mins
LeetCode
Hard
Bfs
Bit-Manipulation
Matrix
LeetCode 864 note: the BFS state is (position, bitmask of keys), so the same cell with different keys is a different node
LeetCode 2963: Count the Number of Good Partitions
·2 mins
LeetCode
Hard
Math
Combinatorics
Hash-Table
Array
LeetCode 2963 note: all occurrences of a value must share a part, so last occurrences cut the array into b indivisible blocks; each boundary may be cut or not, giving 2^(b-1)
LeetCode 2376: Count Special Integers
·2 mins
LeetCode
Hard
Dynamic-Programming
Digit-Dp
Math
Bitmask
LeetCode 2376 note: digit DP with state (pos, tight, started, mask); the mask records used digits, and leading zeros must not mark 0 as used
LeetCode 2163: Minimum Difference in Sums After Removal of Elements
·2 mins
LeetCode
Hard
Dynamic-Programming
Heap
Array
LeetCode 2163 note: try every boundary k between the two parts; the left takes the n smallest of nums[:k] (a max-heap) and the right the n largest of nums[k:] (a min-heap), one prefix and one suffix pass
LeetCode 1627: Graph Connectivity With Threshold
·2 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Array
LeetCode 1627 note: no pairwise GCDs; for each z > threshold, connect all multiples of z, O(n log n) unions in total
LeetCode 1944: Number of Visible People in a Queue
·2 mins
LeetCode
Hard
Stack
Monotonic-Stack
LeetCode 1944 note: a decreasing monotonic stack from right to left; everyone popped is visible, and so is the person left on top
LeetCode 420: Strong Password Checker
·4 mins
LeetCode
Hard
Greedy
String
LeetCode 420 note: three length cases; when too long, delete from runs with len % 3 == 0 first to cancel replacements
LeetCode 2193: Minimum Number of Moves to Make Palindrome
·3 mins
LeetCode
Hard
Two-Pointers
Greedy
String
Binary-Indexed-Tree
LeetCode 2193 note: greedily fix the outer pair: take the last character and swap its leftmost partner to the front, costing that index; the unpaired character ends in the middle, costing its distance there
LeetCode 323: Number of Connected Components in an Undirected Graph
·2 mins
LeetCode
Medium
Graph
Dfs
Bfs
Union-Find
LeetCode 323 note: count components with DFS or Union-Find; Union-Find without path compression is much slower
LeetCode 4041: Minimum Operations to Form Subset Sum II
·2 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
Breadth-First-Search
Array
LeetCode 4041 note: with operations in any order, BFS finds every value a number can become (up to sum) with the fewest steps, then the same grouped 0/1 knapsack as 4040
LeetCode 4040: Minimum Operations to Form Subset Sum I
·2 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
Array
LeetCode 4040 note: with multiplications before divisions, the best is always multiply-only or divide-only; list each number’s reachable values and costs, then run a grouped 0/1 knapsack