⭐️  [ Kt, Js, Py3, Cpp ] 🗺  Map (concise + verbose) solutions
Synopsis:\n\nUse a \uD83D\uDDFA map m to store the index i of each character c in the input string s.\n\nAn astute observer will notice the concise solutions us
**Synopsis:**\n\nUse a `\uD83D\uDDFA` map `m` to store the index `i` of each character `c` in the input string `s`.\n\nAn astute observer will notice the concise solutions use the map `m` to track the right-most index `i` of each character `c` in `s` while the verbose solutions use the map `m` to track the left-most index `i` of each character `c` in `s`.\n\n**`\uD83D\uDCDD` Notes:**\n* The solutions below are in reverse chronological order, ie. I dervied the concise solutions from the verbose solutions.\n* The "concise" C++ solution showcases how C++ poorly expresses "concise" functional programming syntax via mutable lambdas\n\n---\n\n**`\u2B50\uFE0F` Concise Solutions:** (multi-pass)\n\n*Kotlin*\n```\nclass Solution {\n    fun maxLengthBetweenEqualCharacters(s: String): Int {\n        var m = mutableMapOf<Char, Int>()\n        s.forEachIndexed { i, c -> m[c] = i }\n        return s.mapIndexed{ i, c -> m[c]!! - i - 1 }.max()!!  // -1 for (i..j) non-inclusive\n    }\n}\n```\n\n*Javascript*\n```\nlet maxLengthBetweenEqualCharacters = (s, m = new Map()) => {\n    s.split(\'\').forEach((c, i) => m.set(c, i));\n    return Math.max(...s.split(\'\').map((c, i) => m.get(c) - i - 1));  // -1 for (i..j) non-inclusive\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str, best = -1) -> int:\n        m = {c: i for i, c in enumerate(s)}\n        return max([m[c] - i - 1 for i, c in enumerate(s)])  # -1 for (i..j) non-inclusive\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using Map = unordered_map<char, int>;\n    int maxLengthBetweenEqualCharacters(string s, Map m = {}, VI cand = {}) {\n        for_each(s.begin(), s.end(), [i = -1, &m](auto c) mutable { m[c] = ++i; });\n        transform(s.begin(), s.end(), back_inserter(cand), [i = -1, &m](auto c) mutable { return m[c] - ++i - 1; });  // -1 for (i..j) non-inclusive\n        return *max_element(cand.begin(), cand.end());\n    }\n};\n```\n\n\n---\n\n**`\u2B50\uFE0F` Verbose Solutions:** (single-pass)\n\n*Kotlin*\n```\nclass Solution {\n    fun maxLengthBetweenEqualCharacters(s: String): Int {\n        var best = -1\n        var m = mutableMapOf<Char, Int>()\n        s.forEachIndexed { i, c ->\n            if (m.contains(c))\n                best = maxOf(best, i - m[c]!! - 1)  // -1 for (i..j) non-inclusive\n            else\n                m[c] = i\n        }\n        return best\n    }\n}\n```\n\n*Javascript*\n```\nlet maxLengthBetweenEqualCharacters = (s, m = new Map(), best = -1) => {\n    s.split(\'\').forEach((c, i) => {\n        if (m.has(c))\n            best = Math.max(best, i - m.get(c) - 1);  // -1 for (i..j) non-inclusive\n        else\n            m.set(c, i);\n    });\n    return best;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def maxLengthBetweenEqualCharacters(self, s: str, best = -1) -> int:\n        m = {}\n        for i, c in enumerate(s):\n            if c in m:\n                best = max(best, i - m[c] - 1)  # -1 for (i..j) non-inclusive\n            else:\n                m[c] = i\n        return best\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using Map = unordered_map<char, int>;\n    int maxLengthBetweenEqualCharacters(string s, Map m = {}, int best = -1) {\n        int N = s.size();\n        for (auto i{ 0 }; i < N; ++i)\n            if (m.find(s[i]) != m.end())\n                best = max(best, i - m[s[i]] - 1);  // -1 for (i..j) non-inclusive\n            else\n                m[s[i]] = i;\n        return best;\n    }\n};\n```
[]