Complete the code to initialize the 2D array for dynamic programming.
int[,] dp = new int[[1]];We add 1 to lengths to include the base case row and column for empty substrings.
Complete the code to update the DP table when characters match.
if (s1[i - 1] == s2[j - 1]) dp[i, j] = dp[i - 1, j - 1] [1] 1;
When characters match, we extend the previous substring length by 1.
Fix the error in updating the maximum length found so far.
if (dp[i, j] [1] maxLen) maxLen = dp[i, j];
We update maxLen only if current dp[i, j] is greater than maxLen.
Fill both blanks to complete the nested loops iterating over strings.
for (int i = [1]; i <= s1.Length; i++) { for (int j = [2]; j <= s2.Length; j++) {
Loops start from 1 because DP array includes base case at index 0.
Fill all three blanks to return the longest common substring from the input strings.
return s1.Substring([1] - [2], [3]);
Substring starts at startIndex - maxLen and has length maxLen.
