human
Give me a code to find Union and Intersection of two unsorted arrays and the other steps required given the following:
Find Union and Intersection of two unsorted arrays | Prints union of arr1 [ 0. . n1 - 1 ] and arr2 [ 0. . n2 - 1 ].
Prints intersection of arr1 [ 0. . n1 - 1 ] and arr2 [ 0. . n2 - 1 ].
Driver Program.
Function call"
Solution in Python:
assistant
#Here is code to find Union and Intersection of two unsorted arrays and the other steps required.
 def printUnion ( arr1 , arr2 , n1 , n2 ) :
	hs = set ( )
	for i in range ( 0 , n1 ) :
		hs . add ( arr1 [ i ] )
	for i in range ( 0 , n2 ) :
		hs . add ( arr2 [ i ] )
	print ( " Union : " )
	for i in hs :
		print ( i , end = " ▁ " )
	print ( " " )
def printIntersection ( arr1 , arr2 , n1 , n2 ) :
	hs = set ( )
	for i in range ( 0 , n1 ) :
		hs . add ( arr1 [ i ] )
	print ( " Intersection : " )
	for i in range ( 0 , n2 ) :
		if arr2 [ i ] in hs :
			print ( arr2 [ i ] , end = " ▁ " )
arr1 = [ 7 , 1 , 5 , 2 , 3 , 6 ]
arr2 = [ 3 , 8 , 6 , 20 , 7 ]
n1 = len ( arr1 )
n2 = len ( arr2 )
printUnion ( arr1 , arr2 , n1 , n2 )
printIntersection ( arr1 , arr2 , n1 , n2 )