Complete the code to initialize the 2D list for dynamic programming.
dp = [[0] * (len(s2) + 1) for _ in [1]]
We create a 2D list with rows equal to length of s1 + 1 to include empty substring cases.
Complete the code to update the dp table when characters match.
if s1[i - 1] == s2[j - 1]: dp[i][j] = dp[i - 1][[1]] + 1
We look diagonally up-left in the dp table at dp[i-1][j-1] to extend the substring length.
Fix the error in the code that resets dp when characters do not match.
else: dp[i][j] = [1]
When characters don't match, the longest common substring ending here is zero.
Fill both blanks to update the maximum length and ending index of the substring.
if dp[i][j] > [1]: max_len = dp[i][j] end_index = [2]
Update max_len if current dp value is greater, and store the ending index as i-1 (string index).
Fill all three blanks to return the longest common substring from s1.
return s1[[1] - [2] + 1 : [3] + 1]
The substring starts at end_index - max_len + 1 and ends at end_index (inclusive).
