Complete the code to initialize the 2D array for dynamic programming.
int[,] dp = new int[[1], [2]];
The dp array size must be one more than each string length to handle empty prefixes.
Complete the code to check if characters at current indices match.
if (s1[i - 1] [1] s2[j - 1])
We check if characters are equal to extend the subsequence.
Fix the error in updating dp when characters match.
dp[i, j] = dp[i - 1, j - 1] [1] 1;
When characters match, add 1 to the previous diagonal value.
Fill both blanks to update dp when characters do not match.
dp[i, j] = Math.[1](dp[i - 1, j], dp[i, [2] - 1]);
We take the maximum of dp[i-1,j] and dp[i,j-1] to find the longest subsequence so far.
Fill all three blanks to complete the LCS length calculation loop.
for (int i = 1; i [1] s1.Length + 1; i++) { for (int j = 1; j [2] s2.Length + 1; j++) { if (s1[i - 1] == s2[j - 1]) { dp[i, j] = dp[i - 1, j - 1] [3] 1; } else { dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]); } } }
The loops run from 1 up to but not including length + 1, using < operator. When characters match, add 1 to dp[i-1,j-1].
