Suppose we have a string s, we have to find the length of the longest substring with same characters.
So, if the input is like "abbbaccabbbba", then the output will be 4, as there are four consecutive b's.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s): if len(s)==0: return 0 s+=' ' ct=1 tem=1 for i in range(len(s)-1): if s[i]==s[i+1]: tem+=1 else: ct=max(tem,ct) tem=1 return ct ob = Solution() print(ob.solve("abbbaccabbbba"))