💥💥Beats 100% on runtime and memory [EXPLAINED]
\n\n\n\n# Intuition\nThe solution uses a bitmask to represent the frequency of digits in the substring, allowing us to efficiently determine if a substring can 
![image.png](https://assets.leetcode.com/users/images/930a763a-e830-4206-815c-700c10ddba17_1727383411.5563166.png)\n\n\n\n# Intuition\nThe solution uses a bitmask to represent the frequency of digits in the substring, allowing us to efficiently determine if a substring can form a palindrome. By toggling bits for each digit, we can track which digits have odd counts. As we traverse the string, we keep track of the first occurrence of each bitmask in a dictionary. If we encounter the same bitmask again, it means we can form a palindrome from the substring between these two indices. Additionally, we check for palindromes that can have one odd-count digit by toggling each bit. This approach ensures we efficiently find the longest awesome substring in linear time.\n\n# Approach\nBitmasking: Each digit (0-9) is represented by a bit in an integer. This allows us to efficiently track the counts of each digit. A digit contributes to the palindromic structure if it appears an even number of times, except for one digit which can appear an odd number of times (the middle digit in a palindrome).\n\nTracking First Occurrences: We maintain a dictionary to store the first occurrence of each bitmask. This helps in calculating the length of the substring quickly.\n\nFinding Maximum Length: For each character in the string, we check if the current bitmask has been seen before. If it has, it means we can form a palindrome up to that index. We also check for all possible single-digit toggles to account for palindromes that can have one odd-count digit.\n\n# Complexity\n- Time complexity:\nO(n), where n is the length of the string, because we iterate through the string once and perform constant-time operations for each character.\n\n- Space complexity:\nO(1), since the bitmask only uses a fixed number of integers (for 10 digits) and the dictionary will not grow beyond the number of distinct bitmask configurations.\n\n# Code\n```csharp []\npublic class Solution\n{\n    public int LongestAwesome(string s)\n    {\n        // Initialize the length of the longest awesome substring\n        int maxLength = 0;\n        \n        // A dictionary to store the first occurrence of each bitmask\n        Dictionary<int, int> seen = new Dictionary<int, int>();\n        \n        // Initial condition: an empty substring has a bitmask of 0\n        seen[0] = -1;\n        \n        // Variable to maintain the current bitmask\n        int bitmask = 0;\n        \n        for (int i = 0; i < s.Length; i++)\n        {\n            // Toggle the bit corresponding to the current digit\n            bitmask ^= (1 << (s[i] - \'0\'));\n            \n            // Check if the current bitmask has been seen before\n            if (seen.ContainsKey(bitmask))\n            {\n                // Update the maxLength if we found a longer awesome substring\n                maxLength = Math.Max(maxLength, i - seen[bitmask]);\n            }\n            else\n            {\n                // Record the first occurrence of the current bitmask\n                seen[bitmask] = i;\n            }\n            \n            // Check for palindromic potential by toggling each bit (for odd counts)\n            for (int j = 0; j < 10; j++)\n            {\n                int toggleMask = bitmask ^ (1 << j);\n                if (seen.ContainsKey(toggleMask))\n                {\n                    maxLength = Math.Max(maxLength, i - seen[toggleMask]);\n                }\n            }\n        }\n        \n        return maxLength;\n    }\n}\n\n```
['Bitmask', 'C#']