Check if a Palindromic String can be formed by concatenating Substrings of two given Strings | Function to check if a palindromic string can be formed from the substring of given strings ; Boolean array to mark presence of characters ; Check if any of the character of str2 is already marked ; If a common character is found ; If no common character is found ; Driver Code
function check ( str1 , str2 ) { var mark = Array ( 26 ) . fill ( false ) ; var n = str1 . length , m = str2 . length ; for ( var i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' ' ] = true ; } for ( var i = 0 ; i < m ; i ++ ) { if ( mark [ str2 [ i ] - ' ' ] ) return true ; } return false ; } var str1 = " " , str2 = " " ; if ( check ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;