human
Give me a code to queries to find the minimum array sum possible by removing elements from either end and the other steps required given the following:
Queries to find the minimum array sum possible by removing elements from either end | Function to find the minimum sum for each query after removing elements from either ends.
Traverse the query array.
Traverse the array from the front.
If element equals val , then break out of loop.
Traverse the array from rear.
If element equals val , break.
Prthe minimum of the two as the answer.
Driver Code.
Function Call"
Solution in Python:
assistant
#Here is code to queries to find the minimum array sum possible by removing elements from either end and the other steps required.
 def minSum ( arr , N , Q , M ) :
	for i in range ( M ) :
		val = Q [ i ]
		front , rear = 0 , 0
		for j in range ( N ) :
			front += arr [ j ]
			if ( arr [ j ] == val ) :
				break
		for j in range ( N - 1 , - 1 , - 1 ) :
			rear += arr [ j ]
			if ( arr [ j ] == val ) :
				break
		print ( min ( front , rear ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 1 ]
	N = len ( arr )
	Q = [ 7 , 6 ]
	M = len ( Q )
	minSum ( arr , N , Q , M )