Efficient JS solution - Bit manipulation (Beat 100% time)
\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\n\n# Complexity\n- let d = number of diferent digits = 10\n- Time complexity: O(n + 2^
![image.png](https://assets.leetcode.com/users/images/07318e0d-272c-45b6-9b95-0f3fd3778692_1705489334.1899076.png)\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\n\n# Complexity\n- let `d = number of diferent digits = 10`\n- Time complexity: $$O(n + 2^d)$$\n- Space complexity: $$O(2^d)$$\n\n# Code\n```js\nlet first = new Int32Array(1024);\n\n/**\n * @param {string} s\n * @return {number}\n */\nvar longestAwesome = function (s) {\n  first.fill(1e9);\n  first[0] = -1;\n\n  let res = 1;\n  let cur = 0;\n  let n = s.length;\n\n  for (let i = 0; i < n; ++i) {\n    cur ^= 1 << (s.charCodeAt(i) - 48);\n    res = Math.max(\n      res,\n      i -\n        Math.min(\n          first[cur],\n          first[cur ^ 1],\n          first[cur ^ 2],\n          first[cur ^ 4],\n          first[cur ^ 8],\n          first[cur ^ 16],\n          first[cur ^ 32],\n          first[cur ^ 64],\n          first[cur ^ 128],\n          first[cur ^ 256],\n          first[cur ^ 512]\n        )\n    );\n\n    if (first[cur] > i) first[cur] = i;\n  }\n\n  return res;\n};\n```
['Bit Manipulation', 'JavaScript']