Zepruv › Coding problems

Largest Substring Between Two Equal Characters

Easy · Hash Table, String

Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.
A substring is a contiguous sequence of characters within a string.

Example 1

Input: s = "aa"
Output: 0

The optimal substring here is an empty substring between the two 'a's.

Example 2

Input: s = "abca"
Output: 2

The optimal substring here is "bc".

Example 3

Input: s = "cbzxy"
Output: -1

There are no characters that appear twice in s.

Constraints

Starter code (python)

class Solution(object):
    def maxLengthBetweenEqualCharacters(self, s):
        """
        :type s: str
        :rtype: int
        """
        

Related problems

Previous: Count Substrings That Differ by One Character · Next: Lexicographically Smallest String After Applying Operations · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.