Count of ways to split given string into two non | Function to check whether the substring from l to r is palindrome or not ; If characters at l and r differ ; Not a palindrome ; If the string is a palindrome ; Function to count and return the number of possible splits ; Stores the count of splits ; Check if the two substrings after the split are palindromic or not ; If both are palindromes ; Print the final count ; Driver Code
def isPalindrome ( l , r , s ) : NEW_LINE INDENT while ( l <= r ) : NEW_LINE INDENT if ( s [ l ] != s [ r ] ) : NEW_LINE INDENT return bool ( False ) NEW_LINE DEDENT l += 1 NEW_LINE r -= 1 NEW_LINE DEDENT return bool ( True ) NEW_LINE DEDENT def numWays ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE ans = 0 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if ( isPalindrome ( 0 , i , s ) and isPalindrome ( i + 1 , n - 1 , s ) ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT S = " aaaaa " NEW_LINE print ( numWays ( S ) ) NEW_LINE