Check if a Palindromic String can be formed by concatenating Substrings of two given Strings | C ++ Program to implement the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string str1 , string str2 ) { vector < bool > mark ( 26 , false ) ; int n = str1 . size ( ) , m = str2 . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' a ' ] = true ; } for ( int i = 0 ; i < m ; i ++ ) { if ( mark [ str2 [ i ] - ' a ' ] ) return true ; } return false ; } int main ( ) { string str1 = " abca " , str2 = " efad " ; if ( check ( str1 , str2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }