human
Minimum value of X to make all array elements equal by either decreasing or increasing by X | Function that returns the minimum value of X.
Declare a set.
Iterate in the array element and insert them into the set.
If unique elements is 1.
Unique elements is 2.
Get both el2 and el1.
Check if they are even.
If there are 3 unique elements.
Get three unique elements.
Check if their difference is same.
More than 3 unique elements.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to minimum value of X to make all array elements equal by either decreasing or increasing by X and the other steps required.
 def findMinimumX ( a , n ) :
	st = set ( )
	for i in range ( n ) :
		st . add ( a [ i ] )
	if ( len ( st ) == 1 ) :
		return 0
	if ( len ( st ) == 2 ) :
		st = list ( st )
		el1 = st [ 0 ]
		el2 = st [ 1 ]
		if ( ( el2 - el1 ) % 2 == 0 ) :
			return int ( ( el2 - el1 ) / 2 )
		else :
			return ( el2 - el1 )
	if ( len ( st ) == 3 ) :
		st = list ( st )
		el1 = st [ 0 ]
		el2 = st [ 1 ]
		el3 = st [ 2 ]
		if ( ( el2 - el1 ) == ( el3 - el2 ) ) :
			return el2 - el1
		else :
			return - 1
	return - 1
if __name__ == ' _ _ main _ _ ' :
	a = [ 1 , 4 , 4 , 7 , 4 , 1 ]
	n = len ( a )
	print ( findMinimumX ( a , n ) )