C# - 100% Runtime - 92% Memory - Happy New Year!
\n\nHappy New Year and great success to everybody!\n\n# Intuition\nWe need to save the values of First and Last found letters, then return the biggest differenc
![image.png](https://assets.leetcode.com/users/images/4fe199f3-4550-417d-b4bf-b6d23f874369_1703983698.0272934.png)\n\n**Happy New Year and great success to everybody!**\n\n# Intuition\nWe need to save the values of `First` and `Last` found letters, then return the biggest difference found.\n\n# Approach\nI made a custom class `Letter` to easily update values and return the difference in one function call.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\npublic class Solution\n{\n    private class Letter\n    {\n        int First { get; set; } = -1;\n        int Second { get; set; } = -1;\n\n        public int UpdateAndGetDifference(int num)\n        {\n            if (First == -1)\n            {\n                First = num;\n\n                return -1;\n            }\n\n            Second = num;\n\n            return Second - First - 1;\n        }\n    }\n\n    public int MaxLengthBetweenEqualCharacters(string s)\n    {\n        if (s.Length <= 1)\n        {\n            return -1;\n        }\n\n        Letter[] letters = new Letter[26];\n\n        for (int i = 0; i < 26; i++)\n        {\n            letters[i] = new();\n        }\n\n        int maxDifference = -1;\n\n        for (int i = 0; i < s.Length; i++)\n        {\n            Letter letter = letters[s[i] - \'a\'];\n\n            maxDifference = Math.Max(maxDifference, letter.UpdateAndGetDifference(i));\n        }\n\n        return maxDifference;\n    }\n}\n```\n\n---\n![image.png](https://assets.leetcode.com/users/images/4772b402-dd7d-40e4-b5be-a44376818bb2_1703983834.7573934.png)
['C#']