human
Replace every element with the smallest of the others | Python3 code for the above approach ..
There should be atleast two elements.
If current element is smaller than firstSmallest then update both firstSmallest and secondSmallest.
If arr [ i ] is in between firstSmallest and secondSmallest then update secondSmallest.
Replace every element by smallest of all other elements.
Print the modified array ..
Driver code"
Solution in Python:
 Give me a code to replace every element with the smallest of the others and the other steps required?
assistant
#Here is code to replace every element with the smallest of the others and the other steps required.
 def ReplaceElements ( arr , n ) :
	if ( n < 2 ) :
		print ( " Invalid ▁ Input " )
		return
	firstSmallest = 10 ** 18
	secondSmallest = 10 ** 18
	for i in range ( n ) :
		if ( arr [ i ] < firstSmallest ) :
			secondSmallest = firstSmallest
			firstSmallest = arr [ i ]
		elif ( arr [ i ] < secondSmallest and arr [ i ] != firstSmallest ) :
			secondSmallest = arr [ i ]
	for i in range ( n ) :
		if ( arr [ i ] != firstSmallest ) :
			arr [ i ] = firstSmallest
		else :
			arr [ i ] = secondSmallest
	for i in arr :
		print ( i , end = " , ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 2 , 1 , 3 ]
	n = len ( arr )
	ReplaceElements ( arr , n )