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.
packagesolve_problems;/* * Cuddle time * Vu Nguyen Phuong Chi * Miss you */importjava.math.BigInteger;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.Collections;importjava.util.Comparator;importjava.util.HashMap;importjava.util.Set;importjava.util.HashSet;importjava.util.Map;importjava.util.Scanner;publicclassSolve_problems{staticintcommonChild(Strings1,Strings2){int[][]dp=newint[s1.length()+1][s2.length()+1];for(inti=1;i<=s1.length();i++){for(intj=1;j<=s2.length();j++){if(s1.charAt(i-1)==s2.charAt(j-1)){dp[i][j]=dp[i-1][j-1]+1;}else{dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);}}}returndp[s1.length()][s2.length()];}publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);// Read the size of the listStringa=sc.next(),b=sc.next();System.out.println(commonChild(a,b));sc.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 →