@@ -0,0 +1,1729 @@
+package org.santhoshkumar.DynamicProgramming;%0A%0A/**%0A * Created by sk010962 on 10/14/2015.%0A */%0Apublic class LongestCommonSubString %7B%0A%0A    //Bottom up DP approach%0A    public int solve(String one, String two)%7B%0A        int rows = one.length()+1;%0A        int cols = two.length()+1;%0A        int%5B%5D%5B%5D matrix = new int%5Brows%5D%5Bcols%5D;%0A        int max = 0;%0A%0A        for (int i = 0; i %3C rows; i++)%7B%0A            matrix%5Bi%5D%5B0%5D= 0;%0A        %7D%0A        for (int i = 0; i %3C cols; i++)%7B%0A            matrix%5B0%5D%5Bi%5D= 0;%0A        %7D%0A%0A        for (int i = 1; i %3C rows; i++)%7B%0A            for(int j = 1; j %3C cols; j++) %7B%0A                if(one.charAt(i-1) == two.charAt(j-1)) %7B%0A                    matrix%5Bi%5D%5Bj%5D = 1 + matrix%5Bi-1%5D%5Bj-1%5D;%0A                    max = Math.max(max, matrix%5Bi%5D%5Bj%5D);%0A                %7Delse%7B%0A                    matrix%5Bi%5D%5Bj%5D = 0;%0A                %7D%0A            %7D%0A        %7D%0A        return max;%0A    %7D%0A%0A    public int solve2(String one, String two)%7B%0A        return solveRecur(one, two, false);%0A    %7D%0A%0A    // Top Down recursive approach%0A    private int solveRecur(String strOne, String strTwo, boolean equalCheck)%7B%0A        if (strOne.length() == 0 %7C%7C strTwo.length() == 0)%7B%0A            return 0;%0A        %7D%0A%0A        if(equalCheck)%7B%0A            if(strOne.charAt(0)== strTwo.charAt(0))%7B%0A                return 1+ solveRecur(strOne.substring(1), strTwo.substring(1), true);%0A            %7Delse%7B%0A                return 0;%0A            %7D%0A        %7D%0A%0A        int temp = -1;%0A        if(strOne.charAt(0)== strTwo.charAt(0))%7B%0A            temp = 1+ solveRecur(strOne.substring(1), strTwo.substring(1), true);%0A        %7D%0A        return Math.max(temp, Math.max(solveRecur(strOne, strTwo.substring(1),false),solveRecur(strOne.substring(1),strTwo, false)));%0A%0A    %7D%0A%7D%0A

Longest common sub string