human
Write me a code to find all duplicate and missing numbers in given permutation array of 1 to N and the other steps required given the following:
Find all duplicate and missing numbers in given permutation array of 1 to N | Function to find the duplicate and the missing elements over the range [ 1 , N ].
Stores the missing and duplicate numbers in the array arr [ ].
Traverse the given array arr [ ].
Check if the current element is not same as the element at index arr [ i ] - 1 , then swap.
Otherwise , increment the index.
Traverse the array again.
If the element is not at its correct position.
Stores the missing and the duplicate elements.
Print the Missing Number.
Print the Duplicate Number.
Driver code"
Solution in Python:
assistant
#Here is code to find all duplicate and missing numbers in given permutation array of 1 to N and the other steps required.
 def findElements ( arr , N ) :
	i = 0 ;
	missing = [ ] ;
	duplicate = set ( ) ;
	while ( i != N ) :
		if ( arr [ i ] != arr [ arr [ i ] - 1 ] ) :
			t = arr [ i ]
			arr [ i ] = arr [ arr [ i ] - 1 ]
			arr [ t - 1 ] = t
		else :
			i += 1 ;
	for i in range ( N ) :
		if ( arr [ i ] != i + 1 ) :
			missing . append ( i + 1 ) ;
			duplicate . add ( arr [ i ] ) ;
	print ( " Missing ▁ Numbers : ▁ " , end = " " ) ;
	for it in missing :
		print ( it , end = " ▁ " ) ;
	print ( " Duplicate Numbers : " , end = " " ) ;
	for it in list ( duplicate ) :
		print ( it , end = ' ▁ ' ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 2 , 2 , 4 , 5 , 7 ] ;
	N = len ( arr ) ;
	findElements ( arr , N ) ;