human
Write me a code to maximum consecutive numbers present in an array and the other steps required given the following:
Maximum consecutive numbers present in an array | Python3 program to find largest consecutive numbers present in arr ..
We insert all the array elements into unordered set ..
check each possible sequence from the start then update optimal length.
if current element is the starting element of a sequence.
Then check for next elements in the sequence.
increment the value of array element and repeat search in the set.
Update optimal length if this length is more . To get the length as it is incremented one by one.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to maximum consecutive numbers present in an array and the other steps required.
 def findLongestConseqSubseq ( arr , n ) :
	S = set ( ) ;
	for i in range ( n ) :
		S . add ( arr [ i ] ) ;
	ans = 0 ;
	for i in range ( n ) :
		if S . __contains__ ( arr [ i ] ) :
			j = arr [ i ] ;
			while ( S . __contains__ ( j ) ) :
				j += 1 ;
			ans = max ( ans , j - arr [ i ] ) ;
	return ans ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 94 , 93 , 1000 , 5 , 92 , 78 ] ;
	n = len ( arr ) ;
	print ( findLongestConseqSubseq ( arr , n ) ) ;