package leetcode;

/**
 * https://leetcode.com/problems/largest-substring-between-two-equal-characters/
 */
public class Problem1624 {
    public int maxLengthBetweenEqualCharacters(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1624 prob = new Problem1624();
        System.out.println(prob.maxLengthBetweenEqualCharacters("aa")); // 0
        System.out.println(prob.maxLengthBetweenEqualCharacters("abca")); // 2
        System.out.println(prob.maxLengthBetweenEqualCharacters("cbzxy")); // -1
        System.out.println(prob.maxLengthBetweenEqualCharacters("cabbac")); // 4
        System.out.println(prob.maxLengthBetweenEqualCharacters("aaaaa")); // 3
        System.out.println(prob.maxLengthBetweenEqualCharacters("abdefghdxyz")); // 4
        System.out.println(prob.maxLengthBetweenEqualCharacters("aaxyza")); // 4
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -225,696 +225,535 @@
     
-// TODO%0A        return 0
+int%5B%5D indexes = new int%5B26%5D;%0A        Arrays.fill(indexes, -1)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1624 prob = new Problem1624();%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22aa%22)); // 0%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22abca%22)); // 2%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22cbzxy%22)); // -1%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22cabbac%22)); // 4%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22aaaaa%22)); // 3%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22abdefghdxyz%22)); // 4%0A        System.out.println(prob.maxLengthBetweenEqualCharacters(%22aaxyza%22)); // 4
+for (int i = s.length() - 1; i %3E= 0; i--) %7B%0A            int index = indexes%5Bs.charAt(i) - 'a'%5D;%0A            if (index == -1) %7B%0A                indexes%5Bs.charAt(i) - 'a'%5D = i;%0A            %7D%0A        %7D%0A        int answer = -1;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            int index = indexes%5Bs.charAt(i) - 'a'%5D;%0A            if (index %3E i) %7B%0A                answer = Math.max(answer, index - i - 1);%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1624