We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'commonChild' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. STRING s1# 2. STRING s2#defcommonChild(s1,s2):# Write your code heren=len(s1)g=len(s2)m=[]foriinrange(n+1):m.append([])for_inrange(g+1):m[i].append(0)foriinrange(n):forjinrange(g):ifs1[i]==s2[j]:m[i+1][j+1]=max(m[i][j]+1,m[i+1][j-1])continuem[i+1][j+1]=max(m[i+1][j],m[i][j+1])returnm[-1][-1]if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')s1=input()s2=input()result=commonChild(s1,s2)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
Code in Python 3