human
What is a code to minimum possible value of D which when added to or subtracted from K repeatedly obtains every array element and the other steps required given the following:
Minimum possible value of D which when added to or subtracted from K repeatedly obtains every array element | Recursive function tox previous gcd of a and b.
Function to find the maximum value of D such that every element in the array can be obtained by performing K + D or K - D.
Traverse the array arr [ ].
Update arr [ i ].
Stores GCD of the array.
Iterate over the range [ 1 , N ].
Update the value of D.
Print the value of D.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum possible value of D which when added to or subtracted from K repeatedly obtains every array element and the other steps required.
 def gcd ( a , b ) :
	if ( b == 0 ) :
		return a
	return gcd ( b , a % b )
def findMaxD ( arr , N , K ) :
	for i in range ( 0 , N ) :
		arr [ i ] = abs ( arr [ i ] - K )
	D = arr [ 0 ]
	for i in range ( 1 , N ) :
		D = gcd ( D , arr [ i ] )
	return D
arr = [ 1 , 7 , 11 ]
N = len ( arr )
K = 3
print ( findMaxD ( arr , N , K ) )