human
Length of longest subsequence whose difference between maximum and minimum ASCII value of characters is exactly one | Function to find the maximum length of subsequence having difference of ASCII value of longest and smallest character as 1.
Stores frequency of characters.
Iterate over characters of the string.
Stores the resultant length of subsequence.
Check if there exists any elements with ASCII value one less than character ch.
Size of current subsequence.
Update the value of ans.
Print the resultant count.
Driver Code"
Solution in Python:
assistant
#Here is code to length of longest subsequence whose difference between maximum and minimum ASCII value of characters is exactly one and the other steps required.
 def maximumLengthSubsequence ( str ) :
	mp = { }
	for ch in str :
		if ch in mp . keys ( ) :
			mp [ ch ] += 1
		else :
			mp [ ch ] = 1
	ans = 0
	for ch in str :
		if chr ( ord ( ch ) - 1 ) in mp . keys ( ) :
			curr_max = mp [ ch ]
			if chr ( ord ( ch ) - 1 ) in mp . keys ( ) :
				curr_max += mp [ chr ( ord ( ch ) - 1 ) ]
			ans = max ( ans , curr_max )
	print ( ans )
S = " acbbebcg "
maximumLengthSubsequence ( S )