human
Can you provide a code to check whether Arithmetic Progression can be formed from the given array and the other steps required given the following:
Check whether Arithmetic Progression can be formed from the given array | Returns true if a permutation of arr [ 0. . n - 1 ] can form arithmetic progression.
Sort array.
After sorting , difference between consecutive elements must be same ..
Driver code"
Solution in Python:
assistant
#Here is code to check whether Arithmetic Progression can be formed from the given array and the other steps required.
 def checkIsAP ( arr , n ) :
	if ( n == 1 ) : return True
	arr . sort ( )
	d = arr [ 1 ] - arr [ 0 ]
	for i in range ( 2 , n ) :
		if ( arr [ i ] - arr [ i - 1 ] != d ) :
			return False
	return True
arr = [ 20 , 15 , 5 , 0 , 10 ]
n = len ( arr )
print ( " Yes " ) if ( checkIsAP ( arr , n ) ) else print ( " No " )