human
Find maximum sum taking every Kth element in the array | Function to return the maximum sum for every possible sequence such that a [ i ] + a [ i + k ] + a [ i + 2 k ] + ... + a [ i + qk ] is maximized.
Initialize the maximum with the smallest value.
Initialize the sum array with zero.
Iterate from the right.
Update the sum starting at the current element.
Update the maximum so far.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find maximum sum taking every Kth element in the array and the other steps required.
 def maxSum ( arr , n , K ) :
	maximum = - 2 ** 32 ;
	sum = [ 0 ] * n
	for i in range ( n - 1 , - 1 , - 1 ) :
		if ( i + K < n ) :
			sum [ i ] = sum [ i + K ] + arr [ i ]
		else :
			sum [ i ] = arr [ i ] ;
		maximum = max ( maximum , sum [ i ] )
	return maximum ;
arr = [ 3 , 6 , 4 , 7 , 2 ]
n = len ( arr ) ;
K = 2
print ( maxSum ( arr , n , K ) )