import java.util.*; public class Solution { public static String findLCS(int n, int m, String s1, String s2){ // step-1 create a matrix int[][] t = new int[n+1][m+1]; // step-2 intialise the matrix with base condition for(int i=0; i0 && j>0) { if(s1.charAt(i-1) == s2.charAt(j-1)) { s += s1.charAt(i-1); i--; j--; } else { if(t[i-1][j] > t[i][j-1]) i--; else j--; } } // Reverse the LCS string to get the correct order return new StringBuilder(s).reverse().toString(); } }