Check if an array element is concatenation of two elements from another array | C ++ program for the above approach ; Function to find elements present in the array b [ ] which are concatenation of any pair of elements in the array a [ ] ; Stores if there doesn 't any such  element in the array brr[] ; Stored the size of both the arrays ; Store the presence of an element of array a [ ] ; Traverse the array a [ ] ; Traverse the array b [ ] ; Traverse over all possible concatenations of b [ i ] ; Update right and left parts ; Check if both left and right parts are present in a [ ] ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findConcatenatedNumbers ( vector < int > a , vector < int > b ) { bool ans = true ; int n1 = a . size ( ) ; int n2 = b . size ( ) ; unordered_map < int , int > cnt ; for ( int i = 0 ; i < n1 ; i ++ ) { cnt [ a [ i ] ] = 1 ; } for ( int i = 0 ; i < n2 ; i ++ ) { int left = b [ i ] ; int right = 0 ; int mul = 1 ; while ( left > 9 ) { right += ( left % 10 ) * mul ; left /= 10 ; mul *= 10 ; if ( cnt [ left ] == 1 && cnt [ right ] == 1 ) { ans = false ; cout << b [ i ] << " ▁ " ; } } } if ( ans ) cout << " - 1" ; } int main ( ) { vector < int > a = { 2 , 34 , 4 , 5 } ; vector < int > b = { 26 , 24 , 345 , 4 , 22 } ; findConcatenatedNumbers ( a , b ) ; return 0 ; }