text. Find the longest substring (a contiguous piece of text) that contains at most two different letters, and return its length.text='kkokmmo' → 4
The substring "kkok" uses just k and o and has length 4.
text='abcabc' → 2
Any three letters in a row are all different here, so no stretch is longer than 2.
text.length ≤ 10⁵text consists of lowercase English letterstext='kkokmmo'
4
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.