Check if an array element is concatenation of two elements from another array | Python3 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
from collections import defaultdict NEW_LINE def findConcatenatedNumbers ( a , b ) : NEW_LINE INDENT ans = True NEW_LINE n1 = len ( a ) NEW_LINE n2 = len ( b ) NEW_LINE cnt = defaultdict ( int ) NEW_LINE for i in range ( n1 ) : NEW_LINE INDENT cnt [ a [ i ] ] = 1 NEW_LINE DEDENT for i in range ( n2 ) : NEW_LINE INDENT left = b [ i ] NEW_LINE right = 0 NEW_LINE mul = 1 NEW_LINE while ( left > 9 ) : NEW_LINE INDENT right += ( left % 10 ) * mul NEW_LINE left //= 10 NEW_LINE mul *= 10 NEW_LINE if ( cnt [ left ] == 1 and cnt [ right ] == 1 ) : NEW_LINE INDENT ans = False NEW_LINE print ( b [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if ( ans ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 2 , 34 , 4 , 5 ] NEW_LINE b = [ 26 , 24 , 345 , 4 , 22 ] NEW_LINE findConcatenatedNumbers ( a , b ) NEW_LINE DEDENT