class Solution { // idea: Find the LCS and then substract the length of LCS from sum of both strings length /** Recursion*/ public static int minSuperSeq(String s1, String s2) { int n = s1.length(); int m = s2.length(); int length = findLCS(s1, s2, n, m); return (n+m-length); } public static int findLCS(String s1, String s2, int n, int m) { if(n == 0 || m == 0) return 0; // choice diagram if(s1.charAt(n-1) == s2.charAt(m-1)) { return 1 + findLCS(s1, s2, n-1, m-1); } else { int choice1 = findLCS(s1, s2, n-1, m); int choice2 = findLCS(s1, s2, n, m-1); return Math.max(choice1, choice2); } } /** Memoization*/ public static int minSuperSeq(String s1, String s2) { int n = s1.length(); int m = s2.length(); int[][] t = new int[n+1][m+1]; for(int i=0; i