java solution using indexOf(),lastIndexOf(),storing spaces in arraylist and return max from list
\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        if(s.length()==0){\n            return -1;\n        }\n        ArrayList
```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        if(s.length()==0){\n            return -1;\n        }\n        ArrayList<Integer> space=new ArrayList<>();\n        for(int i=0;i<s.length();i++){\n        char a=s.charAt(i);\n        int ind=s.indexOf(a,0);\n        int last=s.lastIndexOf(a);\n            if(ind==-1)\n            space.add(ind);\n        else\n            space.add(last-(i+1));\n        }\n        return Collections.max(space);\n        }\n}\n```
['Java']