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
def findCount ( Arr1 , Arr2 ) : NEW_LINE INDENT MAX = max ( max ( Arr1 ) , max ( Arr2 ) ) ; NEW_LINE Count = [ 0 for i in range ( 2 * MAX + 1 ) ] NEW_LINE n = len ( Arr1 ) ; NEW_LINE m = len ( Arr2 ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT element = Arr1 [ i ] + Arr2 [ j ] ; NEW_LINE Count [ element ] += 1 ; NEW_LINE DEDENT DEDENT for i in range ( 1 , 2 * MAX + 1 ) : NEW_LINE INDENT if ( Count [ i ] > 0 ) : NEW_LINE INDENT print ( i , " - > " , Count [ i ] ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr1 = [ 1 , 2 ] ; NEW_LINE arr2 = [ 1 , 2 , 1 ] ; NEW_LINE findCount ( arr1 , arr2 ) ; NEW_LINE DEDENT