o(n) just by one pointer and indexOf()
```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int end = s.length()-1;\n        int res=-1;\n        while(end>=0){\
```\nclass Solution {\n    public int maxLengthBetweenEqualCharacters(String s) {\n        int end = s.length()-1;\n        int res=-1;\n        while(end>=0){\n            int a = s.indexOf(s.charAt(end));\n            if(a!=end)\n                res = Math.max(res, end-a-1);\n            end--;\n        }\n        return res;\n    }\n}
['Java']