human
Find a subarray whose sum is divisible by size of the array | Function to find a subarray whose sum is a multiple of N.
Prefix sum array to store cumulative sum.
Single state dynamic programming relation for prefix sum array.
Generating all sub - arrays.
If the sum of the sub - array [ i : j ] is a multiple of N.
If the function reaches here it means there are no subarrays with sum as a multiple of N.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find a subarray whose sum is divisible by size of the array and the other steps required.
 def CheckSubarray ( arr , N ) :
	presum = [ 0 for i in range ( N + 1 ) ]
	for i in range ( 1 , N + 1 ) :
		presum [ i ] = presum [ i - 1 ] + arr [ i - 1 ]
	for i in range ( 1 , N + 1 ) :
		for j in range ( i , N + 1 ) :
			if ( ( presum [ j ] - presum [ i - 1 ] ) % N == 0 ) :
				print ( i - 1 , j - 1 )
				return
	print ( " - 1" )
arr = [ 7 , 5 , 3 , 7 ]
N = len ( arr )
CheckSubarray ( arr , N )