human
Longest subsequence with different adjacent characters | Function to find the longest Subsequence with different adjacent character.
Length of the string s.
Previously picked character.
If the current character is different from the previous then include this character and update previous character.
Driver Code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to longest subsequence with different adjacent characters and the other steps required.
 def longestSubsequence ( s ) :
	n = len ( s ) ;
	answer = 0 ;
	prev = ' - ' ;
	for i in range ( 0 , n ) :
		if ( prev != s [ i ] ) :
			prev = s [ i ] ;
			answer += 1 ;
	return answer ;
str = " ababa " ;
print ( longestSubsequence ( str ) ) ;