Given two unsorted arrays , find all pairs whose sum is x | Function to find all pairs in both arrays whose sum is equal to given value x ; Insert all elements of first array in a hash ; Subtract sum from second array elements one by one and check it 's present in  array first or not ; Driver code
def findPairs ( arr1 , arr2 , n , m , x ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT s . add ( arr1 [ i ] ) NEW_LINE DEDENT for j in range ( 0 , m ) : NEW_LINE INDENT if ( ( x - arr2 [ j ] ) in s ) : NEW_LINE INDENT print ( ( x - arr2 [ j ] ) , ' ' , arr2 [ j ] ) NEW_LINE DEDENT DEDENT DEDENT arr1 = [ 1 , 0 , - 4 , 7 , 6 , 4 ] NEW_LINE arr2 = [ 0 , 2 , 4 , - 3 , 2 , 1 ] NEW_LINE x = 8 NEW_LINE n = len ( arr1 ) NEW_LINE m = len ( arr2 ) NEW_LINE findPairs ( arr1 , arr2 , n , m , x ) NEW_LINE