human
Maximize length of longest non | Function to find the length of the longest non - decreasing array that can be generated.
Stores the length of the longest non - decreasing array that can be generated from the array.
Stores index of start pointer.
Stores index of end pointer.
Stores previously inserted element into the new array.
Traverse the array.
If A [ start ] is less than or equal to A [ end ].
If no element inserted into the newly generated array.
Update prev.
Update res.
Update start.
If A [ start ] is greater than or equal to prev.
Update res.
Update prev.
Update start.
If A [ end ] is greater than or equal to prev.
Update res.
Update prev.
Update end.
If A [ end ] is greater than A [ start ].
If no element inserted into the newly generated array.
Update prev.
Update res.
Update end.
If A [ end ] is greater than or equal to prev.
Update res.
Update prev.
Update end.
If A [ start ] is greater than or equal to prev.
Update res.
Update prev.
Update start.
Driver Code.
Function call"
Solution in Python:
assistant
#Here is code to maximize length of longest non and the other steps required.
 def findLongestNonDecreasing ( A , N ) :
	res = 0 ;
	start = 0 ;
	end = N - 1 ;
	prev = - 1 ;
	while ( start <= end ) :
		if ( A [ start ] <= A [ end ] ) :
			if ( prev == - 1 ) :
				prev = A [ start ] ;
				res += 1
				start += 1
			else :
				if ( A [ start ] >= prev ) :
					res += 1
					prev = A [ start ] ;
					start += 1
				elif ( A [ end ] >= prev ) :
					res += 1
					prev = A [ end ] ;
					end -= 1
				else :
					break ;
		else :
			if ( prev == - 1 ) :
				prev = A [ end ] ;
				res += 1
				end -= 1
			else :
				if ( A [ end ] >= prev ) :
					res += 1
					prev = A [ end ] ;
					end -= 1
				elif ( A [ start ] >= prev ) :
					res += 1
					prev = A [ start ] ;
					start += 1
				else :
					break ;
	return res
if __name__ == " _ _ main _ _ " :
	A = [ 1 , 1 , 3 , 5 , 4 , 3 , 6 , 2 , 1 ]
	N = len ( A )
	print ( findLongestNonDecreasing ( A , N ) ) ;