https://leetcode.com/problems/largest-substring-between-two-equal-characters/description/ Easy

Решение

class Solution {
    fun maxLengthBetweenEqualCharacters(s: String): Int {
        val first = IntArray(26) { -1 }
        var ans = -1
        for (i in s.indices) {
            val c = s[i] - 'a'
            if (first[c] == -1) first[c] = i
            else ans = maxOf(ans, i - first[c] - 1)
        }
        return ans
    }
}