human
Write 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 element from either ends till each value Q [ i ].
Stores the prefix sum from both the ends of the array.
Traverse the array from front.
Insert it into the map m1.
Traverse the array in reverse.
Insert it into the map m2.
Traverse the query array.
Print the minimum of the two values 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 minOperations ( arr , N , Q , M ) :
	m1 = { }
	m2 = { }
	front = 0
	rear = 0
	for i in range ( N ) :
		front += arr [ i ]
		m1 [ arr [ i ] ] = front
	for i in range ( N - 1 , - 1 , - 1 ) :
		rear += arr [ i ]
		m2 [ arr [ i ] ] = rear
	for i in range ( M ) :
		print ( min ( m1 [ Q [ i ] ] , m2 [ Q [ i ] ] ) , end = " ▁ " )
arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 1 ]
N = len ( arr )
Q = [ 7 , 6 ]
M = len ( Q )
minOperations ( arr , N , Q , M )