text of lowercase English letters. The gap of a substring is the largest difference between the counts of two letters that **both occur** in that substring (the same letter may be taken twice, giving 0).
Find the largest gap over all non-empty substrings of text (a substring is a contiguous piece of the string).text="bbabbbb" → 5
The whole string has six bs and one a, a gap of 6 − 1 = 5. Leaving out the a gives only bs and a gap of 0.
text="ppqpq" → 2
ppqp has three ps and one q, a gap of 2. Nothing does better.
text="xyz" → 0
Every letter occurs once, so every gap is 0.
len(text) ≤ 10⁴text consists of lowercase English letterstext="bbabbbb"
5
Run checks the first 3 tests in your browser. Submit checks all 27 tests on the server, hidden ones included.