I'm having an issue with the longest common substring algorithm presented in the article.
I'm getting an incorrect output when I run the following code:
Thanks!
I'm getting an incorrect output when I run the following code:
Code:
def lcs(X, Y, m, n):
if m == 0 or n == 0:
return 0;
elif X[m-1] == Y[n-1]:
return 1 + lcs(X, Y, m-1, n-1);
else:
return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
X = "abcdxyz"
Y = "xyzabcd"
print("Length of Longest Common Substring is ", lcs(X , Y, len(X), len(Y)))
The output I'm getting is 0 instead of the expected 4. Could someone please help me troubleshoot this issue?
Thanks!