text and a number limit. Find the longest substring (a contiguous piece of text) that contains at most limit different letters, and return its length.text='pqpqrrqp', limit=2 → 4
The substrings "pqpq" and "qrrq" each use two different letters and have length 4; nothing longer stays within two.
text='zzz', limit=0 → 0
Zero different letters allows only the empty substring.
text.length ≤ 5 · 10⁴text consists of lowercase English letterslimit ≤ 50text='pqpqrrqp', limit=2
4
Run checks the first 3 tests in your browser. Submit checks all 120 tests on the server, hidden ones included.