human
Can you provide a code to construction of Longest Increasing Subsequence ( N log N ) and the other steps required given the following:
Construction of Longest Increasing Subsequence ( N log N ) | Binary search.
Add boundary case , when array n is zero Depend on smart pointers.
Initialized with - 1.
it will always point to empty location.
new smallest value.
arr [ i ] wants to extend largest subsequence.
arr [ i ] wants to be a potential condidate of future subsequence It will replace ceil value in tailIndices.
driver code"
How can the above be solved in Python?
assistant
#Here is code to construction of Longest Increasing Subsequence ( N log N ) and the other steps required.
 def GetCeilIndex ( arr , T , l , r , key ) :
	while ( r - l > 1 ) :
		m = l + ( r - l ) // 2
		if ( arr [ T [ m ] ] >= key ) :
			r = m
		else :
			l = m
	return r
def LongestIncreasingSubsequence ( arr , n ) :
	tailIndices = [ 0 for i in range ( n + 1 ) ]
	prevIndices = [ - 1 for i in range ( n + 1 ) ]
	len = 1
	for i in range ( 1 , n ) :
		if ( arr [ i ] < arr [ tailIndices [ 0 ] ] ) :
			tailIndices [ 0 ] = i
		elif ( arr [ i ] > arr [ tailIndices [ len - 1 ] ] ) :
			prevIndices [ i ] = tailIndices [ len - 1 ]
			tailIndices [ len ] = i
			len += 1
		else :
			pos = GetCeilIndex ( arr , tailIndices , - 1 , len - 1 , arr [ i ] )
			prevIndices [ i ] = tailIndices [ pos - 1 ]
			tailIndices [ pos ] = i
	print ( " LIS ▁ of ▁ given ▁ input " )
	i = tailIndices [ len - 1 ]
	while ( i >= 0 ) :
		print ( arr [ i ] , " ▁ " , end = " " )
		i = prevIndices [ i ]
	print ( )
	return len
arr = [ 2 , 5 , 3 , 7 , 11 , 8 , 10 , 13 , 6 ]
n = len ( arr )
print ( " LIS size " , LongestIncreasingSubsequence ( arr , n ) )