text of lowercase English letters. Call a substring (a contiguous non-empty piece) single-letter if all its characters are the same, such as "kkk" or "q", but not "kq".
Find the length of the longest single-letter substring that occurs in text at least three times. Occurrences may overlap: in "bbbb" the substring "bb" occurs three times, starting at positions 0, 1 and 2. If no single-letter substring occurs three times, return -1.text='xxxyxxyx' → 2
"x" occurs 6 times and "xx" exactly three times: twice inside "xxx" and once in the middle. "xxx" occurs only once, so the answer is 2.
text='mnoonm' → -1
Each letter appears only twice, so no single-letter substring occurs three times.
text='ttttttt' → 5
text consists of lowercase English letterstext='xxxyxxyx'
2
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.