human
Maximize subarrays count containing the maximum and minimum Array element after deleting at most one element | Returns the count of subarrays which contains both the maximum and minimum elements in the given vector.
Initialize the low and high of array.
If current element is less than least element.
If current element is more than highest element.
If current element is equal to low or high then update the pointers.
Update number of subarrays.
Return the result.
Function to find the maximum count of subarrays.
Iterate the array to find the maximum and minimum element.
Vector after removing the minimum element.
Using assignment operator to copy one vector to other.
Vector after removing the maximum element.
Given array.
Function Call"
Solution in Python:
assistant
#Here is code to maximize subarrays count containing the maximum and minimum Array element after deleting at most one element and the other steps required.
 def proc ( v ) :
	n = len ( v ) ;
	low = v [ n - 1 ]
	high = v [ n - 1 ]
	p1 = n
	p2 = n ;
	ans = 0 ;
	for i in range ( n - 1 , - 1 , - 1 ) :
		x = v [ i ] ;
		if ( x < low ) :
		low = x ;
		ans = 0 ;
		elif ( x > high ) :
		high = x ;
		ans = 0 ;
		if ( x == low ) : p1 = i ;
		if ( x == high ) : p2 = i ;
		ans += n - max ( p1 , p2 ) ;
	return ans ;
def subarray ( v ) :
	n = len ( v ) ;
	if ( n <= 1 ) :
		return n ;
	ans = proc ( v ) ;
	low = v [ 0 ]
	pos_low = 0
	high = v [ 0 ]
	pos_high = 0
	for i in range ( 1 , n ) :
		x = v [ i ] ;
		if ( x < low ) :
		low = x ;
		pos_low = i ;
		elif ( x > high ) :
		high = x ;
		pos_high = i ;
	u = v [ : ] ;
	del u [ pos_low ] ;
	ans = max ( ans , proc ( u ) ) ;
	w = v [ : ] ;
	del w [ pos_high ] ;
	return max ( ans , proc ( w ) ) ;
v = [ ] ;
v . append ( 7 ) ;
v . append ( 2 ) ;
v . append ( 5 ) ;
v . append ( 4 ) ;
v . append ( 3 ) ;
v . append ( 1 ) ;
print ( subarray ( v ) ) ;