human
Rearrange an array such that arr [ i ] = i | Function to tranform the array.
Iterate over the array.
Check is any ar [ j ] exists such that ar [ j ] is equal to i.
Iterate over array.
If not present.
Print the output.
Driver Code.
Function Call"
Solution in Python:
 ... Write me a code to rearrange an array such that arr [ i ] = i and the other steps required?
assistant
#Here is code to rearrange an array such that arr [ i ] = i and the other steps required.
 def fixArray ( ar , n ) :
	for i in range ( n ) :
		for j in range ( n ) :
			if ( ar [ j ] == i ) :
				ar [ j ] , ar [ i ] = ar [ i ] , ar [ j ]
	for i in range ( n ) :
		if ( ar [ i ] != i ) :
			ar [ i ] = - 1
	print ( " Array ▁ after ▁ Rearranging " )
	for i in range ( n ) :
		print ( ar [ i ] , end = " ▁ " )
ar = [ - 1 , - 1 , 6 , 1 , 9 , 3 , 2 , - 1 , 4 , - 1 ]
n = len ( ar )
fixArray ( ar , n ) ;