Longest Stretch With No Letter Thrice
Return the length of the longest contiguous piece of s in which no letter appears three or more times. Inside the piece each letter may appear once or twice, and different letters are counted separately.
The empty string gives 0. For "aaabb" the piece "aabb" has two of each letter, so the answer is 4; the whole string has three as.
Example 1
s "aaabb"
returns 4
aabb (positions 1 to 4) has no letter three times; any longer piece has three a's.
Example 2
s "abcabcabc"
returns 6
abcabc has every letter twice; adding one more letter makes a third copy of it.
Constraints
0 <= len(s) <= 60shas lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.