Java Solution | O(n)
java []\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int max=-1;\n        for(char ch=\'a\';ch<=\'z\';ch++){\n        
```java []\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int max=-1;\n        for(char ch=\'a\';ch<=\'z\';ch++){\n            max=Math.max(s.lastIndexOf(ch)-s.indexOf(ch)-1,max);\n        }\n        return max;\n    }\n}\n```\n``` java []\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int[] table = new int[26];\n        Arrays.fill(table,-1);\n        int i=0, max=-1;\n        for(char ch:s.toCharArray()){\n            if(table[ch-\'a\']!=-1){\n                max=Math.max(max,i-table[ch-\'a\']-1);\n            }else{\n                table[ch-\'a\']=i;\n            }\n            i++;\n        }\n        return max;\n    }\n}\n```
['Java']