human
Queries to find minimum sum of array elements from either end of an array | Function to calculate the minimum sum from either end of the arrays for the given queries.
Traverse the query [ ] array.
Stores sum from start and end of the array.
Calculate distance from start.
Calculate distance from end.
Driver Code"
Solution in Python:
assistant
#Here is code to queries to find minimum sum of array elements from either end of an array and the other steps required.
 def calculateQuery ( arr , N , query , M ) :
	for i in range ( M ) :
		X = query [ i ]
		sum_start = 0
		sum_end = 0
		for j in range ( N ) :
			sum_start += arr [ j ]
			if ( arr [ j ] == X ) :
				break
		for j in range ( N - 1 , - 1 , - 1 ) :
			sum_end += arr [ j ]
			if ( arr [ j ] == X ) :
				break
		print ( min ( sum_end , sum_start ) , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 30 ]
	queries = [ 6 , 5 ]
	N = len ( arr )
	M = len ( queries )
	calculateQuery ( arr , N , queries , M )