Length of Longest Palindrome Substring | Function to obtain the length of the longest palindromic substring ; Length of given string ; Stores the maximum length ; Iterate over the string ; Iterate over the string ; Check for palindrome ; If string [ i , j - i + 1 ] is palindromic ; Return length of LPS ; Given string ; Function Call
function longestPalSubstr ( str ) { var n = str . length ; var maxLength = 1 , start = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { for ( var j = i ; j < str . length ; j ++ ) { var flag = 1 ; for ( var k = 0 ; k < ( j - i + 1 ) / 2 ; k ++ ) if ( str [ i + k ] != str [ j - k ] ) flag = 0 ; if ( flag && ( j - i + 1 ) > maxLength ) { start = i ; maxLength = j - i + 1 ; } } } return maxLength ; } var str = " " ; document . write ( longestPalSubstr ( str ) ) ;