text: Maximize [ length ( X ) / 2 ^ ( XOR ( X , Y ) ) ] by choosing substrings X and Y from string A and B respectively | Function to find the length of the longest common substring of the string X and Y ; LCSuff [ i ] [ j ] stores the lengths of the longest common suffixes of substrings ; Itearate over strings A and B ; If first row or column ; If matching is found ; Otherwise , if matching is not found ; Finally , return the resultant maximum value LCS ; Driver Code ; Function Call
code: function LCSubStr ( A , B , m , n ) { let LCSuff = Array ( m + 1 ) . fill ( Array ( n + 1 ) ) ; let result = 0 ; for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) LCSuff [ i ] [ j ] = 0 ; else if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) { LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ; if ( LCSuff [ i ] [ j ] > result ) { result = LCSuff [ i ] [ j ] ; } } else LCSuff [ i ] [ j ] = 0 ; } } result ++ ; return result ; } let A = " " ; let B = " " ; let M = A . length ; let N = B . length ; document . write ( LCSubStr ( A , B , M , N ) ) ;