Java
mask = 10 bits represent at a certain time for each number if it appeared even or odd number of times. \n\nwhen a mask reapet itself (or it can be one bit off f
mask = 10 bits represent at a certain time for each number if it appeared even or odd number of times. \n\nwhen a mask reapet itself (or it can be one bit off for the middle char) we got an Awesome substring between the reapetitions.\n \n# Code\n```\nclass Solution {\n\n    public int longestAwesome(String s) {\n        int n = s.length() , max = 0, mask = 0;\n        Map <Integer, Integer> firstMaskAppearanceMap = new HashMap(); // map first time a certain bit mask appear so the next time we know we have an Awesome Substring\n\n        firstMaskAppearanceMap.put(mask, -1);  // init for 0 \n        for (int j = 0; j < 10; j++){\n            int maskShiftedOne = mask ^ (1 << j); // we alowed to exceed by one char for the middle char, keep track of any mask that is one off our current mask \n            firstMaskAppearanceMap.put(maskShiftedOne, -1); \n        }\n\n        for (int i = 0; i < n; i++){\n            mask ^= 1 << (s.charAt(i) - \'0\');\n            for (int j = 0; j < 10; j++){\n                int maskShiftedOne = mask ^ (1 << j); // as before update every map in proximity 1 char to mask (no need to update mask itself since symmetrical isn\'t optimal unless it\'s of size n)\n                firstMaskAppearanceMap.putIfAbsent(maskShiftedOne, i);\n            }\n            max = Math.max(max, i - firstMaskAppearanceMap.get(mask)); // same mask accured at a lower index - we got an Awesome Substring\n        }\n\n        return max; \n    }\n}\n```\n\n\n\n\n\nsame code less words:\n```\nclass Solution {\n    public int longestAwesome(String s) {\n        int n = s.length() , max = 0, mask = 0;\n        Map <Integer, Integer> map = new HashMap(); \n        map.put(mask, -1);  \n        for (int j = 0; j < 10; j++) map.put(mask ^ (1 << j), -1); \n        for (int i = 0; i < n; i++){\n            mask ^= 1 << (s.charAt(i) - \'0\');\n            for (int j = 0; j < 10; j++) map.putIfAbsent(mask ^ (1 << j), i);\n            max = Math.max(max, i - map.get(mask)); \n        }\n        return max; \n    }\n}\n```
['Java']