Palindrome pair in an array of words ( or strings ) | Utility function to check if a string is a palindrome ; Compare each character from starting with its corresponding character from last ; Function to check if a palindrome pair exists ; Consider each pair one by one ; Concatenate both strings ; Check if the concatenated string is palindrome ; Check for other combination of the two strings ; Driver code
def isPalindrome ( st ) : NEW_LINE INDENT length = len ( st ) NEW_LINE for i in range ( length // 2 ) : NEW_LINE INDENT if ( st [ i ] != st [ length - i - 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def checkPalindromePair ( vect ) : NEW_LINE INDENT for i in range ( len ( vect ) - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , len ( vect ) ) : NEW_LINE INDENT check_str = vect [ i ] + vect [ j ] NEW_LINE if ( isPalindrome ( check_str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT check_str = vect [ j ] + vect [ i ] NEW_LINE if ( isPalindrome ( check_str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT vect = [ " geekf " , " geeks " , " or " , " keeg " , " abc " , " bc " ] NEW_LINE if checkPalindromePair ( vect ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT