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.
defcommonChild(s1,s2):# init a DP table with dimensions (len(s1)+1) x (len(s2)+1)dp=[[0]*(len(s2)+1)for_inrange(len(s1)+1)]# filling the DP tableforiinrange(1,len(s1)+1):forjinrange(1,len(s2)+1):ifs1[i-1]==s2[j-1]:# match founddp[i][j]=dp[i-1][j-1]+1else:# taking max from previous statesdp[i][j]=max(dp[i-1][j],dp[i][j-1])#attheright-bottomofBPthereisthevaluewewantreturndp[len(s1)][len(s2)]
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: