Count of three non | Function that returns true if s [ i ... j ] + s [ k ... l ] + s [ p ... q ] is a palindrome ; Function to return the count of valid sub - strings ; To store the count of required sub - strings ; For choosing the first sub - string ; For choosing the second sub - string ; For choosing the third sub - string ; Check if the concatenation is a palindrome ; Driver code
def isPalin ( i , j , k , l , p , q , s ) : NEW_LINE INDENT start = i ; end = q ; NEW_LINE while ( start < end ) : NEW_LINE INDENT if ( s [ start ] != s [ end ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT start += 1 ; NEW_LINE if ( start == j + 1 ) : NEW_LINE INDENT start = k ; NEW_LINE DEDENT end -= 1 ; NEW_LINE if ( end == p - 1 ) : NEW_LINE INDENT end = l ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT def countSubStr ( s ) : NEW_LINE INDENT count = 0 ; NEW_LINE n = len ( s ) ; NEW_LINE for i in range ( n - 2 ) : NEW_LINE INDENT for j in range ( i , n - 2 ) : NEW_LINE INDENT for k in range ( j + 1 , n - 1 ) : NEW_LINE INDENT for l in range ( k , n - 1 ) : NEW_LINE INDENT for p in range ( l + 1 , n ) : NEW_LINE INDENT for q in range ( p , n ) : NEW_LINE INDENT if ( isPalin ( i , j , k , l , p , q , s ) ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " abca " ; NEW_LINE print ( countSubStr ( s ) ) ; NEW_LINE DEDENT