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):n=len(s1)m=len(s2)# Initialize dp arraydp=[[0]*(m+1)for_inrange(n+1)]# Build dp arrayforiinrange(1,n+1):forjinrange(1,m+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])# The length of the longest common childreturndp[n][m]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Common Child
You are viewing a single comment's thread. Return to all comments →
My Solution in Python 3