Hard
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 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 2328: Number of Increasing Paths in a Grid
·2 mins
LeetCode
Hard
Dynamic-Programming
Grid-Dp
Memoization
Topological-Sort
Matrix
LeetCode 2328 note: strictly increasing means no cycles; dp[cell] = 1 + Σ dp[larger neighbors], processed from largest to smallest value (or by memoized DFS), summed over all cells
LeetCode 1377: Frog Position After T Seconds
·3 mins
LeetCode
Hard
Tree
Dfs
Bfs
Graph
Probability
LeetCode 1377 note: undirected edges, seen must hold nodes, and an early arrival depends on whether the frog can still move
LeetCode 1178: Number of Valid Words for Each Puzzle
·3 mins
LeetCode
Hard
Bit-Manipulation
Hash-Map
Trie
LeetCode 1178 note: a word only matters by its set of letters, so count 26-bit masks and enumerate each puzzle’s submasks