human
Queries to find longest subsequence having no similar adjacent elements with updates | Function to find the length of the longest subsequence such that no two adjacent elements are equal.
Replace element at index x with y.
Since x is 1 - indexed , decrement x by 1.
Keep track of number of elements in subsequence.
If previous element is not same as current element.
Print the desired count.
Driver Code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to queries to find longest subsequence having no similar adjacent elements with updates and the other steps required.
 def longestSubsequence ( N , Q , arr , Queries ) :
	for i in range ( Q ) :
		x = Queries [ i ] [ 0 ]
		y = Queries [ i ] [ 1 ]
		arr [ x - 1 ] = y
		count = 1
		for j in range ( 1 , N ) :
			if ( arr [ j ] != arr [ j - 1 ] ) :
				count += 1
		print ( count , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 1 , 2 , 5 , 2 ]
	N = len ( arr )
	Q = 2
	Queries = [ [ 1 , 3 ] , [ 4 , 2 ] ]
	longestSubsequence ( N , Q , arr , Queries )