longest common subsequence | Sololearn: Learn to code for FREE!


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

2/16/2022 5:10:01 PM

Gajendra Sonare

1 Answer

New Answer


# 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))