human
What is a code to length of the longest substring with no consecutive same letters and the other steps required given the following:
Length of the longest substring with no consecutive same letters | Function to return the length of the required sub - string.
Get the length of the string.
Iterate in the string.
Check for not consecutive.
If cnt greater than maxi.
Re - initialize.
Check after iteration is complete.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to length of the longest substring with no consecutive same letters and the other steps required.
 def longestSubstring ( s ) :
	cnt = 1 ;
	maxi = 1 ;
	n = len ( s ) ;
	for i in range ( 1 , n ) :
		if ( s [ i ] != s [ i - 1 ] ) :
			cnt += 1 ;
		else :
			maxi = max ( cnt , maxi ) ;
			cnt = 1 ;
	maxi = max ( cnt , maxi ) ;
	return maxi ;
if __name__ == " _ _ main _ _ " :
	s = " ccccdeededff " ;
	print ( longestSubstring ( s ) ) ;