longest common subsequence | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

longest common subsequence

I am trying to find longest common subsequence of two strings. I think I have implemented correct logic but it is giving wrong input for a test case. Can someone tell me what's the problem with this code? s = "abcde" t = "acek" it should give 3 for the above test case https://code.sololearn.com/c9O28zPF55i2

16th Feb 2022, 5:10 PM
Gajendra Sonare
Gajendra Sonare - avatar
1 Answer
0
# Hi! This is a way to find common substrings. Maybe it can help you to compare outputs from your code: l = input().split() or ["abcekde", "acekt", "zaqacekyi"] print(max([min(l)[i:j] for i in range(len(min(l))) for j in range(i, len(min(l)) + 1) if all([min(l)[i:j] in wd for wd in l])], key=len))
16th Feb 2022, 5:52 PM
Per Bratthammar
Per Bratthammar - avatar