String
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 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 1028: Recover a Tree From Preorder Traversal
·3 mins
LeetCode
Hard
Tree
Binary-Tree
Dfs
Stack
String
LeetCode 1028 note: a stack holds the path from the root to the current node, so its length is the depth
LeetCode 301: Remove Invalid Parentheses
·4 mins
LeetCode
Hard
Backtracking
Bfs
String
LeetCode 301 note: compute the minimum left and right deletions before backtracking, or BFS one deletion per level and stop at the first valid level
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 4026: Maximum Gap Between Stations
·2 mins
LeetCode
Medium
Two-Pointers
Greedy
String
LeetCode 4026 note: greedily match from the left for each worker’s earliest station and from the right for the latest; splitting between workers i and i+1, the largest gap is latest[i+1] - earliest[i]
LeetCode 1320: Minimum Distance to Type a Word Using Two Fingers
·2 mins
LeetCode
Hard
Dynamic-Programming
State-Machine
String
LeetCode 1320 note: after typing word[i], one finger is always on word[i], so the state is only the other finger’s position; dp[other] is the least distance with the other finger at other
LeetCode 902: Numbers At Most N Given Digit Set
·2 mins
LeetCode
Hard
Dynamic-Programming
Digit-Dp
Math
Binary-Search
String
LeetCode 902 note: digit DP with state (pos, tight, started); before starting, a position can be skipped, representing numbers with fewer digits than n
LeetCode 1092: Shortest Common Supersequence
·5 mins
LeetCode
Hard
Dynamic-Programming
String
LeetCode note for Shortest Common Supersequence, rebuilt from the original learning note
LeetCode 712: Minimum ASCII Delete Sum for Two Strings
·4 mins
LeetCode
Medium
Dynamic-Programming
String
LeetCode note for Minimum ASCII Delete Sum for Two Strings, rebuilt from the original learning note
LeetCode 1312: Minimum Insertion Steps to Make a String Palindrome
·4 mins
LeetCode
Hard
Dynamic-Programming
String
Palindrome
LeetCode note for Minimum Insertion Steps to Make a String Palindrome, rebuilt from the original learning note