JavaScript and TypeScript two pointer traversal explained 82% speed
JavaScript\n\n\nconst longestPalindrome = s => {\n    s = [...s].sort();                    //Group all letters into adjacency groups\n    let singleCounted = f
JavaScript\n\n```\nconst longestPalindrome = s => {\n    s = [...s].sort();                    //Group all letters into adjacency groups\n    let singleCounted = false, len = 0;   //Track whether the single letter in the middle of the palindrome has been accounted for\n    let i = 0, j = 1;                     //Two pointer traversal\n    while (i < s.length){\n        while (s[j] === s[i]) j++;         //Move the second pointer until the boundary of the current adjacency group is reached\n        let group = j - i;                 //Get the size of the group\n        if (!singleCounted && group % 2){  //If the single letter hasn\'t been used yet and the group has an odd length, use the single letter\n            len++;\n            singleCounted = true;\n        }\n        len += group % 2? group-1 : group; //Add the group size or the even part of the group\'s size to the length\n        i = j;                             //Move first pointer to the first unaccounted letter\n    }\n    return len;\n};\n```\n\nTypeScript - difference is had to use join() to cast sorted array of chars back into a string\n\n```\nconst longestPalindrome = (s: string): number => {\n    s = [...s].sort().join(\'\');           //Group all letters into adjacency groups\n    let singleCounted = false, len = 0;   //Track whether the single letter in the middle of the palindrome has been accounted for\n    let i = 0, j = 1;                     //Two pointer traversal\n    while (i < s.length){\n        while (s[j] === s[i]) j++;         //Move the second pointer until the boundary of the current adjacency group is reached\n        let group = j - i;                 //Get the size of the group\n        if (!singleCounted && group % 2){  //If the single letter hasn\'t been used yet and the group has an odd length, use the single letter\n            len++;\n            singleCounted = true;\n        }\n        len += group % 2? group-1 : group; //Add the group size or the even part of the group\'s size to the length\n        i = j;                             //Move first pointer to the first unaccounted letter\n    }\n    return len;\n};\n```
[]