Longest Common Substring | DP | Javascript program using to find length of the longest common substring recursion ; Returns length of function f or longest common substring of X [ 0. . m - 1 ] and Y [ 0. . n - 1 ] ; Driver code
let X , Y ; function lcs ( i , j , count ) { if ( i == 0 j == 0 ) return count ; if ( X [ i - 1 ] == Y [ j - 1 ] ) { count = lcs ( i - 1 , j - 1 , count + 1 ) ; } count = Math . max ( count , Math . max ( lcs ( i , j - 1 , 0 ) , lcs ( i - 1 , j , 0 ) ) ) ; return count ; } let n , m ; X = " " ; Y = " " ; n = X . length ; m = Y . length ; document . write ( lcs ( n , m , 0 ) ) ;