#1624
Largest Substring Between Two Equal Characters
pupil · 300 · lc easy +20 · verified · 68.3% accepted · 1,407 likes · top 75%
Description
Given a string s, find the longest substring that lies strictly between two identical characters. Return its length, or -1 if no character appears more than once in s.
Example 1:
Input: s = "aa"
Output: 0
Explanation: The optimal substring here is an empty substring between the two 'a's.
Example 2:
Input: s = "abca"
Output: 2
Explanation: The optimal substring here is "bc".
Example 3:
Input: s = "cbzxy"
Output: -1
Explanation: There are no characters that appear twice in s.
Code
1
2
3