human
Queries to find the maximum and minimum array elements excluding elements from a given range | Function to find the maximum and minimum array elements up to the i - th index.
Traverse the array.
Compare current value with maximum and minimum values up to previous index.
Function to find the maximum and minimum array elements from i - th index.
Traverse the array in reverse.
Compare current value with maximum and minimum values in the next index.
Function to find the maximum and minimum array elements for each query.
If no index remains after excluding the elements in a given range.
Find maximum and minimum from from the range [ R + 1 , N - 1 ].
Find maximum and minimum from from the range [ 0 , N - 1 ].
Find maximum and minimum values from the ranges [ 0 , L - 1 ] and [ R + 1 , N - 1 ].
Print maximum and minimum value.
Function to perform queries to find the minimum and maximum array elements excluding elements from a given range.
Size of the array.
Size of query array.
prefix [ i ] [ 0 ] : Stores the maximum prefix [ i ] [ 1 ] : Stores the minimum value.
suffix [ i ] [ 0 ] : Stores the maximum suffix [ i ] [ 1 ] : Stores the minimum value.
Function calls to store maximum and minimum values for respective ranges.
Driver Code.
Given array"
Solution in Python:

Write me a code to queries to find the maximum and minimum array elements excluding elements from a given range and the other steps required?
assistant
#Here is code to queries to find the maximum and minimum array elements excluding elements from a given range and the other steps required.
 def prefixArr ( arr , prefix , N ) :
	for i in range ( N ) :
		if ( i == 0 ) :
			prefix [ i ] [ 0 ] = arr [ i ]
			prefix [ i ] [ 1 ] = arr [ i ]
		else :
			prefix [ i ] [ 0 ] = max ( prefix [ i - 1 ] [ 0 ] , arr [ i ] )
			prefix [ i ] [ 1 ] = min ( prefix [ i - 1 ] [ 1 ] , arr [ i ] )
	return prefix
def suffixArr ( arr , suffix , N ) :
	for i in range ( N - 1 , - 1 , - 1 ) :
		if ( i == N - 1 ) :
			suffix [ i ] [ 0 ] = arr [ i ]
			suffix [ i ] [ 1 ] = arr [ i ]
		else :
			suffix [ i ] [ 0 ] = max ( suffix [ i + 1 ] [ 0 ] , arr [ i ] )
			suffix [ i ] [ 1 ] = min ( suffix [ i + 1 ] [ 1 ] , arr [ i ] )
	return suffix
def maxAndmin ( prefix , suffix , N , L , R ) :
	maximum , minimum = 0 , 0
	if ( L == 0 and R == N - 1 ) :
		print ( " No ▁ maximum ▁ and ▁ minimum ▁ value " )
		return
	elif ( L == 0 ) :
		maximum = suffix [ R + 1 ] [ 0 ]
		minimum = suffix [ R + 1 ] [ 1 ]
	elif ( R == N - 1 ) :
		maximum = prefix [ L - 1 ] [ 0 ]
		minimum = prefix [ R - 1 ] [ 1 ]
	else :
		maximum = max ( prefix [ L - 1 ] [ 0 ] , suffix [ R + 1 ] [ 0 ] )
		minimum = min ( prefix [ L - 1 ] [ 1 ] , suffix [ R + 1 ] [ 1 ] )
	print ( maximum , minimum )
def MinMaxQueries ( a , queries ) :
	N = len ( arr )
	q = len ( queries )
	prefix = [ [ 0 for i in range ( 2 ) ] for i in range ( N ) ]
	suffix = [ [ 0 for i in range ( 2 ) ] for i in range ( N ) ]
	prefix = prefixArr ( arr , prefix , N )
	suffix = suffixArr ( arr , suffix , N )
	for i in range ( q ) :
		L = queries [ i ] [ 0 ]
		R = queries [ i ] [ 1 ]
		maxAndmin ( prefix , suffix , N , L , R )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 1 , 8 , 3 , 5 , 7 , 4 ]
	queries = [ [ 4 , 6 ] , [ 0 , 4 ] , [ 3 , 7 ] , [ 2 , 5 ] ]
	MinMaxQueries ( arr , queries )