human
Write me a code to count distinct elements after adding each element of First Array with Second Array and the other steps required given the following:
Count distinct elements after adding each element of First Array with Second Array | Function to find Occurrence of each element from 1 to 2 * MAX.
Initialise MAX.
Count vector to store count of each element from 1 to 2 * MAX Count = new int [ 2 * MAX + 1 ].
.
Size of Arr1 and Arr2.
Find the elements of arr3 and increase count of element by 1.
Prthe result.
Driver Code.
Given arrays arr1 and arr2.
Function call"
Solution in Python:
assistant
#Here is code to count distinct elements after adding each element of First Array with Second Array and the other steps required.
 def findCount ( Arr1 , Arr2 ) :
	MAX = max ( max ( Arr1 ) , max ( Arr2 ) ) ;
	Count = [ 0 for i in range ( 2 * MAX + 1 ) ]
	n = len ( Arr1 ) ;
	m = len ( Arr2 ) ;
	for i in range ( n ) :
		for j in range ( m ) :
			element = Arr1 [ i ] + Arr2 [ j ] ;
			Count [ element ] += 1 ;
	for i in range ( 1 , 2 * MAX + 1 ) :
		if ( Count [ i ] > 0 ) :
			print ( i , " - > " , Count [ i ] ) ;
if __name__ == ' _ _ main _ _ ' :
	arr1 = [ 1 , 2 ] ;
	arr2 = [ 1 , 2 , 1 ] ;
	findCount ( arr1 , arr2 ) ;