human
Subsequence with maximum pairwise absolute difference and minimum size | Function to find the subsequence with maximum absolute difference.
To store the resultant subsequence.
First element should be included in the subsequence.
Traverse the given array arr [ ].
If current element is greater than the previous element.
If the current element is not the local maxima then continue.
Else push it in subsequence.
If the current element is less then the previous element.
If the current element is not the local minima then continue.
Else push it in subsequence.
Last element should also be included in subsequence.
Print the element.
Driver Code.
Given array.
Function Call"
Solution in Python:
 Write me a code to subsequence with maximum pairwise absolute difference and minimum size and the other steps required?
assistant
#Here is code to subsequence with maximum pairwise absolute difference and minimum size and the other steps required.
 def getSubsequence ( ar ) :
	N = len ( ar )
	ans = [ ]
	ans . append ( ar [ 0 ] )
	for i in range ( 1 , N - 1 ) :
		if ( ar [ i ] > ar [ i - 1 ] ) :
			if ( i < N - 1 and ar [ i ] <= ar [ i + 1 ] ) :
				continue
			else :
				ans . append ( ar [ i ] )
		else :
			if ( i < N - 1 and ar [ i + 1 ] < ar [ i ] ) :
				continue
			else :
				ans . append ( ar [ i ] )
	ans . append ( ar [ N - 1 ] )
	for it in ans :
		print ( it , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 4 , 3 , 5 ]
	getSubsequence ( arr )