human
Longest substring such that no three consecutive characters are same | Function to return the length of the longest substring such that no three consecutive characters are same.
If the length of the given string is less than 3.
Initialize temporary and final ans to 2 as this is the minimum length of substring when length of the given string is greater than 2.
Traverse the string from the third character to the last.
If no three consecutive characters are same then increment temporary count.
Else update the final ans and reset the temporary count.
Driver code"
Solution in Python:
assistant
#Here is code to longest substring such that no three consecutive characters are same and the other steps required.
 def maxLenSubStr ( s ) :
	if ( len ( s ) < 3 ) :
		return len ( s )
	temp = 2
	ans = 2
	for i in range ( 2 , len ( s ) ) :
		if ( s [ i ] != s [ i - 1 ] or s [ i ] != s [ i - 2 ] ) :
			temp += 1
		else :
			ans = max ( temp , ans )
			temp = 2
	ans = max ( temp , ans )
	return ans
s = " baaabbabbb "
print ( maxLenSubStr ( s ) )