Easy to understand solution in java using bit masking
Intuition\nWe can use bitmasking  to mask the characters:\n\n0 -> 0000000001\n1 -> 0000000010\n2 -> 0000000100\n3 -> 0000001000\n4 -> 0000010000\n5 -> 000010000
# Intuition\nWe can use bitmasking  to mask the characters:\n\n0 -> 0000000001\n1 -> 0000000010\n2 -> 0000000100\n3 -> 0000001000\n4 -> 0000010000\n5 -> 0000100000\n6 -> 0001000000\n7 -> 0010000000\n8 -> 0100000000\n9 -> 1000000000\n\n\nNow we know that:\nXOR Operation of two same number is zero:\n\nWe will make use of XOR to find the even length substring which can be arranged to form a pallindrome.\n\nTo get the odd length substring which can be arranged to form a pallindrome we need to try by XOR of all the 10 bitmask of all the 10 characters from 0 to 9 and if it becomes zero then we are pretty sure that \nthat character has occured only once and when you XOR one from your side it makes it zero.\n\nWe will also make use of the concept of hashing here to find the previous seen Values to get the largest length.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int longestAwesome(String s) {\n        HashMap<Integer,Integer> prevSeenIndex = new HashMap();\n        int ans = 0;\n        int mask = 0;\n        prevSeenIndex.put(0,-1);\n        int k =0;\n        for(char c: s.toCharArray())\n        {\n            int no = c-\'0\';\n            int binaryRepresentation = 1<<(no+1);\n            mask = mask^binaryRepresentation;\n            int length = k-prevSeenIndex.getOrDefault(mask,k)+1;\n            ans = Math.max(length,ans);\n            for(int i=0;i<=9;i++)\n            {\n                 binaryRepresentation = 1<<(i+1);\n                length= k - prevSeenIndex.getOrDefault(mask^binaryRepresentation,k)+1;\n                ans = Math.max(length,ans);\n            }\n            if(!prevSeenIndex.containsKey(mask))\n                prevSeenIndex.put(mask,k);\n            k++;\n        }\n        return ans-1;\n    }\n\n}\n```
['Java']