Longest Non | Java implementation to find maximum length substring which is not palindrome ; 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
public class GFG { static Boolean isPalindrome ( String str ) { int n = str . length ( ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) if ( str . charAt ( i ) != str . charAt ( n - i - 1 ) ) return false ; return true ; } static int maxLengthNonPalinSubstring ( String str ) { int n = str . length ( ) ; char ch = str . charAt ( 0 ) ; int i = 1 ; for ( i = 1 ; i < n ; i ++ ) if ( str . charAt ( i ) != ch ) break ; if ( i == n ) return 0 ; if ( isPalindrome ( str ) ) return n - 1 ; return n ; } public static void main ( String args [ ] ) { String str = " abba " ; System . out . println ( " Maximum ▁ Length ▁ = ▁ " + maxLengthNonPalinSubstring ( str ) ) ; } }