human
Length of longest strict bitonic subsequence | function to find length of longest strict bitonic subsequence.
hash table to map the array element with the length of the longest subsequence of which it is a part of and is the last / first element of that subsequence.
arrays to store the length of increasing and decreasing subsequences which end at them or start from them.
to store the length of longest strict bitonic subsequence.
traverse the array elements from left to right.
initialize current length for element arr [ i ] as 0.
if ' arr [ i ] -1' is in 'inc  .
update arr [ i ] subsequence length in ' inc ' and in len_inc [ ].
traverse the array elements from right to left.
initialize current length for element arr [ i ] as 0.
if ' arr [ i ] -1' is in 'dcr  .
update arr [ i ] subsequence length in ' dcr ' and in len_dcr [ ].
calculating the length of all the strict bitonic subsequence.
required longest length strict bitonic subsequence.
Driver Code"
How can the above be solved in Python?
 ... What is a code to length of longest strict bitonic subsequence and the other steps required?
assistant
#Here is code to length of longest strict bitonic subsequence and the other steps required.
 def longLenStrictBitonicSub ( arr , n ) :
	inc , dcr = dict ( ) , dict ( )
	len_inc , len_dcr = [ 0 ] * n , [ 0 ] * n
	longLen = 0
	for i in range ( n ) :
		len = 0
		if inc . get ( arr [ i ] - 1 ) in inc . values ( ) :
			len = inc . get ( arr [ i ] - 1 )
		inc [ arr [ i ] ] = len_inc [ i ] = len + 1
	for i in range ( n - 1 , - 1 , - 1 ) :
		len = 0
		if dcr . get ( arr [ i ] - 1 ) in dcr . values ( ) :
			len = dcr . get ( arr [ i ] - 1 )
		dcr [ arr [ i ] ] = len_dcr [ i ] = len + 1
	for i in range ( n ) :
		if longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) :
			longLen = len_inc [ i ] + len_dcr [ i ] - 1
	return longLen
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 5 , 2 , 3 , 4 , 5 , 3 , 2 ]
	n = len ( arr )
	print ( " Longest ▁ length ▁ strict ▁ bitonic ▁ subsequence ▁ = " , longLenStrictBitonicSub ( arr , n ) )