human
Longest subarray forming an Arithmetic Progression ( AP ) | Function to return the length of longest subarray forming an AP.
Minimum possible length of required subarray is 2.
Stores the length of the current subarray.
Stores the common difference of the current AP.
Stores the common difference of the previous AP.
If the common differences are found to be equal.
Continue the previous subarray.
Start a new subarray.
Update the length to store maximum length.
Update the length to store maximum length.
Return the length of the longest subarray.
Driver Code"
How can the above be solved in Python?
 Can you provide a code to longest subarray forming an Arithmetic Progression ( AP ) and the other steps required?
assistant
#Here is code to longest subarray forming an Arithmetic Progression ( AP ) and the other steps required.
 def getMaxLength ( arr , N ) :
	res = 2
	dist = 2
	curradj = ( arr [ 1 ] - arr [ 0 ] )
	prevadj = ( arr [ 1 ] - arr [ 0 ] )
	for i in range ( 2 , N ) :
		curradj = arr [ i ] - arr [ i - 1 ]
		if ( curradj == prevadj ) :
			dist += 1
		else :
			prevadj = curradj
			res = max ( res , dist )
			dist = 2
	res = max ( res , dist )
	return res
if __name__ == " _ _ main _ _ " :
	arr = [ 10 , 7 , 4 , 6 , 8 , 10 , 11 ]
	N = len ( arr )
	print ( getMaxLength ( arr , N ) )