human
Find position i to split Array such that prefix sum till i | Function to check if there is an element forming G . P . series having common ratio k.
If size of array is less than three then return - 1.
Initialize the variables.
Calculate total sum of array.
Calculate Middle element of G . P . series.
Iterate over the range.
Store the first element of G . P . series in the variable temp.
Return position of middle element of the G . P . series if the first element is in G . P . of common ratio k.
Else return 0.
if middle element is not found in arr [ ].
Driver Code.
Given array"
How can the above be solved in Python?
assistant
#Here is code to find position i to split Array such that prefix sum till i and the other steps required.
 def checkArray ( arr , N , k ) :
	if ( N < 3 ) :
		return - 1
	Sum = 0
	temp = 0
	for i in range ( 0 , N ) :
		Sum += arr [ i ]
	R = ( k * k + k + 1 )
	if ( Sum % R != 0 ) :
		return 0
	Mid = k * ( Sum // R )
	for i in range ( 1 , N - 1 ) :
		temp += arr [ i - 1 ]
		if ( arr [ i ] == Mid ) :
			if ( temp == Mid // k ) :
				return i + 1
			else :
				return 0
	return 0
if __name__ == " _ _ main _ _ " :
	arr = [ 5 , 1 , 4 , 20 , 6 , 15 , 9 , 10 ]
	N = len ( arr )
	K = 2
	print ( checkArray ( arr , N , K ) )