String DP
You know basic string matching. Now solve Edit Distance, LCS variants, and two-sequence alignment problems with multi-dimensional DP tables.
Lessons
1. Introduction to String DP
Sequences, alignment, transformation
2. When to Use String DP
Two strings → dp[i][j]
3. Problem - Regex Matching
LC 10 - dot and star patterns
4. Regex Matching - Why Naive Fails
Star means zero or more of previous
5. Regex Matching - Defining the DP
dp[i][j] = does prefix match?
6. Regex Matching - Transition
Zero times or extend match
7. Regex Matching - Base Cases
Empty vs patterns like a*b*
8. Regex Matching - Implementation
Handle *, then .
9. Regex Matching - Time and Space
O(mn) both time and space
10. Regex Matching - Edge Cases
.* matches everything
11. Lessons from Regex Matching
Operators create branches
12. Problem - Interleaving String
LC 97 - merge two strings
13. Interleaving String - Why DP?
14. Interleaving String - Solution
dp[i][j] uses s3[i+j-1]
15. Interleaving String - Building the State
16. Problem - Palindrome Partitioning
LC 131 - all palindrome partitions
17. Palindrome Partitioning - Solution
Precompute isPalin[i][j]
18. Palindrome Partitioning - Precomputation
Interval DP for palindrome check
19. SCS - Solution
SCS = len1 + len2 - LCS
20. SCS - Reconstruction
Backtrack through LCS table
21. Problem - Longest Palindromic Substring
LC 5 - longest palindrome substring
22. Longest Palindromic Substring - Solution
Expand around center or DP
23. Problem - Word Break
LC 139 - dictionary segmentation
24. Word Break - Solution
dp[i] = prefix can be split?
25. Quiz: String DP Patterns
Which pattern is this?
26. Quiz: String DP Edge Cases
Empty string, single char
27. Common Mistakes in String DP
1-indexed DP, 0-indexed strings
28. Problem - Scramble String
LC 87
29. Scramble String - Implementation
Solution approach
30. Problem - Count Different Palindromic Subsequences
LC 730
31. Count Different Palindromic Subsequences - Implementation
Solution approach
32. Problem - Distinct Subsequences II
LC 940
33. Distinct Subsequences II - Implementation
Solution approach
34. Problem - Palindrome Partitioning III
LC 1278
35. Palindrome Partitioning III - Implementation
Solution approach
36. Problem - Number of Ways to Form Target String
LC 1639
37. Number of Ways to Form Target String - Implementation
Solution approach
38. Section Recap
From edit distance to word break