Longest Non | utility function to check whether a string is palindrome or not ; Check for palindrome . ; palindrome string ; function to find maximum length substring which is not palindrome ; to check whether all characters of the string are same or not ; All characters are same , we can 't  make a non-palindromic string. ; If string is palindrome , we can make it non - palindrome by removing any corner character ; Complete string is not a palindrome . ; Driver Program to test above function
function isPalindrome ( str ) { let n = str . length ; for ( let i = 0 ; i < n / 2 ; i ++ ) { if ( str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } function maxLengthNonPalinSubstring ( str ) { let n = str . length ; let ch = str [ 0 ] ; let i = 1 ; for ( i = 1 ; i < n ; i ++ ) { if ( str [ i ] != ch ) { break ; } } if ( i == n ) return 0 ; if ( isPalindrome ( str ) ) return n - 1 ; return n ; } let str = " " ; document . write ( " " + maxLengthNonPalinSubstring ( str ) ) ;