For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.

For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.

Constraints:
1 ≤ T ≤ 100
1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks

Sample Output:
6
7, I have written this Solution Code: 
    // str is input string
    function longestDistinctSubstr(s) {


const mostRecent = new Map(); // Stores the most recent idx
        let startIdx = 0, res = 0;
        for (let i = 0; i < s.length; i++) {
          if (mostRecent.has(s[i]) && mostRecent.get(s[i]) >= startIdx) {
            res = Math.max(res, i - startIdx);
            startIdx = mostRecent.get(s[i]) + 1;
          }
          mostRecent.set(s[i], i);
        }
        return Math.max(res, s.length - startIdx);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?