Why do we have to keep first row and col of dp matrix as 0.
Longest Common Subsequence
Hey @Ans
For the first row, the empty string " " is compared with the second string. in all the columns of the first row, as there are no common characters, the length of longest common subsequence there has to be 0, same is the case with the first column, so we fill them zero ourselves, they are kind of the base case and we fill the rest of the dp table, by using values in the first row and column.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.