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 if the concatenated string is palindrome ; Driver code
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len / 2 ; i ++ ) if ( str [ i ] != str [ len - i - 1 ] ) return false ; return true ; } function checkPalindromePair ( vect ) { for ( let i = 0 ; i < vect . length - 1 ; i ++ ) { for ( let j = i + 1 ; j < vect . length ; j ++ ) { let check_str = " " ; check_str = check_str + vect [ i ] + vect [ j ] ; if ( isPalindrome ( check_str ) ) return true ; check_str = vect [ j ] + vect [ i ] ; if ( isPalindrome ( check_str ) ) return true ; } } return false ; } let vect = [ " " , " " , " " , " " , " " , " " ] if ( checkPalindromePair ( vect ) == true ) document . write ( " " ) ; else document . write ( " " ) ;