Hard
LeetCode LCR 170: Count Inversions (Sword Offer 51)
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Counting
LCR 170 note: count inversions during the merge step
LeetCode 315: Count of Smaller Numbers After Self
·4 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Binary-Indexed-Tree
Counting
LeetCode 315 note: merge sort with indices, plus a BIT solution
LeetCode 827: Making A Large Island
·3 mins
LeetCode
Hard
Dfs
Bfs
Matrix
Union-Find
LeetCode 827 note: label every island and record its size, then for each 0 add the sizes of the distinct neighboring islands plus 1
LeetCode 212: Word Search II
·2 mins
LeetCode
Hard
Trie
Backtracking
Matrix
LeetCode 212 note: build a Trie of all words, walk it during the grid DFS, remove words once found, and prune empty nodes
LeetCode 3203: Find Minimum Diameter After Merging Two Trees
·3 mins
LeetCode
Hard
Tree
Bfs
Dfs
Graph
Tree-Diameter
LeetCode 3203 note: connect the two centers; the answer is max(d1, d2, ceil(d1/2) + ceil(d2/2) + 1)
LeetCode 305: Number of Islands II
·3 mins
LeetCode
Hard
Union-Find
Hash-Table
Array
LeetCode 305 note: each new land cell adds an island, then merges with neighboring land, subtracting 1 per successful merge; skip repeated positions
LeetCode 1220: Count Vowels Permutation
·2 mins
LeetCode
Hard
Dynamic-Programming
State-Machine
LeetCode 1220 note: state machine DP on the last vowel; turn “what may follow x” around into “what may precede x”
LeetCode 4081: Prime Subset Selection II
·4 mins
LeetCode
Hard
Knapsack-Dp
Number-Theory
LeetCode 4081 note: sieve the primes, then 0/1 knapsack with dp[j] the fewest primes summing to j; adding primes from large to small, a tie gives a smaller first element, so updating on <= yields the lexicographically smallest
LeetCode 2751: Robot Collisions
·3 mins
LeetCode
Hard
Stack
Simulation
Sorting
LeetCode 2751 note: sort by position, push right-moving robots, and let each left-moving robot collide until one side is gone
LeetCode 2584: Split the Array to Make Coprime Products
·3 mins
LeetCode
Hard
Math
Number-Theory
Sieve
Hash-Table
Array
LeetCode 2584 note: coprime products ⇔ no prime factor in both parts; record each prime’s last index, extend reach left to right, and split after i when reach == i
LeetCode 2267: Check if There Is a Valid Parentheses String Path
·3 mins
LeetCode
Hard
Dynamic-Programming
Grid-Dp
Matrix
Bracket-Sequences
LeetCode 2267 note: the state is (r, c, open balance); the balance can be neither negative nor more than the remaining steps; search the states with BFS / DP and succeed at the end with balance 0
LeetCode 1998: GCD Sort of an Array
·3 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Sieve
Sorting
Array
LeetCode 1998 note: numbers in one component can be permuted freely; union each number with its prime factors via SPF, and the array sorts iff each position’s old and new values share a group