C++ Clean Solutions and Comparison between |O(26*N) time, O(1) space| VS |O(N) time, O(26) space| ✓
Hey, well the goal is to go by the letter and find it\'s end points. We can do that using two pointers: O(26*N) time || O(1) space \n\n\nclass Solution {\npubli
Hey, well the goal is to go by the letter and find it\'s end points. We can do that using two pointers: O(26*N) time || O(1) space \n\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int ret = -1, l, r;\n        for (int i = \'a\'; i <= \'z\'; i++) {\n            l = 0, r = s.size() - 1;\n            while (l < r && s[l] != i) l++;\n            while (l < r && s[r] != i) r--;\n            ret = max(ret, r - l - 1);\n        }\n        return ret;\n    }\n};\n```\nThe solution above is good for memory, but time is probably more important (most of the time) than extra 26 memory.\n\nThe best solution (timewise) is to remember first encounter of a letter and use it to calculate our answer: O(N) time || O(26) space\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int m[26] = {};\n        int ret = -1;\n        for (int i = 0; i < s.size(); i++) {\n            int j = m[s[i] - \'a\'];\n            if (j != 0)\n                ret = max(ret, i - j);\n            else \n                m[s[i] - \'a\'] = i + 1;\n        }\n        return ret;\n    }\n};\n```\nOr the same but more unreadable: O(N) time || O(123) space\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int m[123] = {}, ret = -1;\n        for (int i = 0; i < s.size(); ret = max(ret, i - m[s[i++]])) \n            if (m[s[i]] == 0)\n                m[s[i]] = i + 1;\n        return ret;\n    }\n};\n```\nNote: m[123] is such a nice array, it is easy to type 123 and you don\'t have to substact anything from letters as it includes letters up to \'z\' (Also includes uppercase letters, of course, but useless for this problem).
['Two Pointers', 'C']