String DP

You know basic string matching. Now solve Edit Distance, LCS variants, and two-sequence alignment problems with multi-dimensional DP tables.

38 lessons
130 min
Codeforces: 1600-2000LeetCode: 1700-2000

Lessons

1. Introduction to String DP

Sequences, alignment, transformation

2m

2. When to Use String DP

Two strings → dp[i][j]

3m

3. Problem - Regex Matching

LC 10 - dot and star patterns

3m1 problems

4. Regex Matching - Why Naive Fails

Star means zero or more of previous

4m

5. Regex Matching - Defining the DP

dp[i][j] = does prefix match?

4m

6. Regex Matching - Transition

Zero times or extend match

4m

7. Regex Matching - Base Cases

Empty vs patterns like a*b*

3m

8. Regex Matching - Implementation

Handle *, then .

5m1 problems

9. Regex Matching - Time and Space

O(mn) both time and space

3m

10. Regex Matching - Edge Cases

.* matches everything

3m

11. Lessons from Regex Matching

Operators create branches

3m

12. Problem - Interleaving String

LC 97 - merge two strings

3m1 problems

13. Interleaving String - Why DP?

14. Interleaving String - Solution

dp[i][j] uses s3[i+j-1]

4m

15. Interleaving String - Building the State

16. Problem - Palindrome Partitioning

LC 131 - all palindrome partitions

3m1 problems

17. Palindrome Partitioning - Solution

Precompute isPalin[i][j]

4m

18. Palindrome Partitioning - Precomputation

Interval DP for palindrome check

3m

19. SCS - Solution

SCS = len1 + len2 - LCS

4m

20. SCS - Reconstruction

Backtrack through LCS table

3m

21. Problem - Longest Palindromic Substring

LC 5 - longest palindrome substring

4m1 problems

22. Longest Palindromic Substring - Solution

Expand around center or DP

4m1 problems

23. Problem - Word Break

LC 139 - dictionary segmentation

4m1 problems

24. Word Break - Solution

dp[i] = prefix can be split?

4m1 problems

25. Quiz: String DP Patterns

Which pattern is this?

3m1 problems

26. Quiz: String DP Edge Cases

Empty string, single char

3m1 problems

27. Common Mistakes in String DP

1-indexed DP, 0-indexed strings

4m

28. Problem - Scramble String

LC 87

3m1 problems

29. Scramble String - Implementation

Solution approach

5m1 problems

30. Problem - Count Different Palindromic Subsequences

LC 730

3m1 problems

31. Count Different Palindromic Subsequences - Implementation

Solution approach

5m1 problems

32. Problem - Distinct Subsequences II

LC 940

3m1 problems

33. Distinct Subsequences II - Implementation

Solution approach

5m1 problems

34. Problem - Palindrome Partitioning III

LC 1278

3m1 problems

35. Palindrome Partitioning III - Implementation

Solution approach

5m1 problems

36. Problem - Number of Ways to Form Target String

LC 1639

3m1 problems

37. Number of Ways to Form Target String - Implementation

Solution approach

5m1 problems

38. Section Recap

From edit distance to word break

3m

Practice Problems

Ready to start learning?

Access all 38 lessons with interactive content and progress tracking.