common child hackerrank solution

Solutions on MaxInterview for common child hackerrank solution by the best coders in the world

showing results for - "common child hackerrank solution"
Sofie
18 Nov 2017
1def commonChild(s1, s2):
2    m = [[0]*(len(s2)+1) for _ in range(len(s1)+1)]
3    for i,c in enumerate(s1,1):
4        for j,d in enumerate(s2,1):
5            if c == d:
6                m[i][j] = m[i-1][j-1]+1
7            else:
8                m[i][j] = max(m[i][j-1],m[i-1][j])
9                   
10    return m[-1][-1]
11print(commonChild(input(), input()))
12