human
Smallest subsequence with sum of absolute difference of consecutive elements maximized | Function to print the smallest subsequence and its sum.
Final subsequence.
First element is a default endpoint.
Iterating through the array.
Check for monotonically increasing endpoint.
Check for monotonically decreasing endpoint.
Last element is a default endpoint.
Length of final subsequence.
Print the subsequence.
Driver code"
Solution in Python:
 Give me a code to smallest subsequence with sum of absolute difference of consecutive elements maximized and the other steps required?
assistant
#Here is code to smallest subsequence with sum of absolute difference of consecutive elements maximized and the other steps required.
 def getSubsequence ( arr , n ) :
	req = [ ]
	req . append ( arr [ 0 ] )
	for i in range ( 1 , n - 1 ) :
		if ( arr [ i ] > arr [ i + 1 ] and arr [ i ] > arr [ i - 1 ] ) :
			req . append ( arr [ i ] )
		elif ( arr [ i ] < arr [ i + 1 ] and arr [ i ] < arr [ i - 1 ] ) :
			req . append ( arr [ i ] ) ;
	req . append ( arr [ n - 1 ] ) ;
	print ( len ( req ) )
	for x in req :
		print ( x , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 5 , 3 , 6 , 7 , 4 ]
	n = len ( arr )
	getSubsequence ( arr , n )