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 heredp=[[0]*(len(s2)+1)for_inrange(len(s1)+1)]foriinrange(1,len(s1)+1):forjinrange(1,len(s2)+1):ifs1[i-1]==s2[j-1]:dp[i][j]=dp[i-1][j-1]+1else:dp[i][j]=max(dp[i-1][j],dp[i][j-1])returndp[len(s1)][len(s2)]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 →
Python 3: