Posts

Showing posts from May, 2019

How do you find longest common substring ?

Problem statement: Given two strings S1 & S2. Find the longest common substring between S1 & S2. import java.util.ArrayList; import java.util.List; public class LongestCommonSubstring {     public static void main(String[] args) {         String S1 = "LCLC";         String S2 = "CLCL";         //String S3 = "abcdabccab";         //String S4 = "bcdaccabaabc";         List<String> com = commonSubstring(S1, S2);         for (String s: com){             System.out.println(s);         }     }     public static List<String> commonSubstring(String s1, String s2) {         Integer match[][] = new Integer[s1.length()][s2.length()];         int len1 = s1.length();         int len2 = s2.length(); ...