human
Queries to check if array elements from indices [ L , R ] forms an Arithmetic Progression or not | Function to check if the given range of queries form an AP or not in the given array arr [ ].
Stores length of the longest subarray forming AP for every array element.
Iterate over the range [ 0 , N ].
Stores the index of the last element of forming AP.
Iterate until the element at index ( j , j + 1 ) forms AP.
Increment j by 1.
Traverse the current subarray over the range [ i , j - 1 ].
Update the length of the longest subarray at index k.
Update the value of i.
Traverse the given queries.
Print the result.
Otherwise.
Driver Code"
Solution in Python:
 ... What is a code to queries to check if array elements from indices [ L , R ] forms an Arithmetic Progression or not and the other steps required?
assistant
#Here is code to queries to check if array elements from indices [ L , R ] forms an Arithmetic Progression or not and the other steps required.
 def findAPSequence ( arr , N , Q , M ) :
	dp = [ 0 ] * ( N + 5 )
	i = 0
	while i + 1 < N :
		j = i + 1
		while ( j + 1 < N and arr [ j + 1 ] - arr [ j ] == arr [ i + 1 ] - arr [ i ] ) :
			j += 1
		for k in range ( i , j ) :
			dp [ k ] = j - k
		i = j
	for i in range ( M ) :
		if ( dp [ Q [ i ] [ 0 ] ] >= Q [ i ] [ 1 ] - Q [ i ] [ 0 ] ) :
			print ( " Yes " )
		else :
			print ( " No " )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 3 , 5 , 7 , 6 , 5 , 4 , 1 ]
	Q = [ [ 0 , 3 ] , [ 3 , 4 ] , [ 2 , 4 ] ]
	N = len ( arr )
	M = len ( Q )
	findAPSequence ( arr , N , Q , M )