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.
C language solution using dynamic programming (recursion with memory)
intmax(inta,intb){return((a>=b)?(a):(b));}intLSC(char*s1,char*s2,intlen_1,intlen_2,inti,intj,int**Hash_Table){if(i>=len_1||j>=len_2){return0;}elseif(Hash_Table[i][j]!=0){returnHash_Table[i][j];}elseif(s1[i]==s2[j]){//rewrite that code to store the valueintval=1+LSC(s1,s2,len_1,len_2,i+1,j+1,Hash_Table);Hash_Table[i][j]=val;returnval;}else{intval=max(LSC(s1,s2,len_1,len_2,i+1,j,Hash_Table),LSC(s1,s2,len_1,len_2,i,j+1,Hash_Table));Hash_Table[i][j]=val;returnval;}}/* * Complete the 'commonChild' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. STRING s1 * 2. STRING s2 */intcommonChild(char*s1,char*s2){intlen_1=strlen(s1),len_2=strlen(s2);int**Hash_Table=calloc(len_1,sizeof(int*));for(inti=0;i<len_1;i++){Hash_Table[i]=calloc(len_2,sizeof(int));}returnLSC(s1,s2,len_1,len_2,0,0,Hash_Table);}
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 →
C language solution using dynamic programming (recursion with memory)