text. Pick two equal letters in it and count the characters strictly between them. Return the largest such count.
If two equal letters are adjacent, there are 0 characters between them. If no letter repeats, return -1.text="pencil" → -1
All letters are different, so there is no matching pair and the answer is -1.
text="banana" → 3
The first and the last 'a' sit at positions 1 and 5 with "nan" between them, 3 characters. Nothing is wider.
text="zz" → 0
text consists of lowercase English letterstext="pencil"
-1
Run checks the first 3 tests in your browser. Submit checks all 76 tests on the server, hidden ones included.