human
What is a code to longest sub and the other steps required given the following:
Longest sub | Function to return the length of the largest subsequence with non - negative sum.
To store the current sum.
Sort the input array in non - increasing order.
Traverse through the array.
Add the current element to the sum.
Condition when c_sum falls below zero.
Complete array has a non - negative sum.
Driver code"
Solution in Python:
assistant
#Here is code to longest sub and the other steps required.
 def maxLen ( arr , n ) :
	c_sum = 0 ;
	arr . sort ( reverse = True ) ;
	for i in range ( n ) :
		c_sum += arr [ i ] ;
		if ( c_sum < 0 ) :
			return i ;
	return n ;
if __name__ == " _ _ main _ _ " :
	arr = [ 3 , 5 , - 6 ] ;
	n = len ( arr ) ;
	print ( maxLen ( arr , n ) ) ;