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
def check ( str1 , str2 ) : NEW_LINE INDENT mark = [ False for i in range ( 26 ) ] NEW_LINE n = len ( str1 ) NEW_LINE m = len ( str2 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT mark [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] = True NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT if ( mark [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = " abca " NEW_LINE str2 = " efad " NEW_LINE if ( check ( str1 , str2 ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT