Given a string, s , find the length of the longest substring that contains no repeated characters. Example input: s: "nndNfdfdf" Example output : 4 Explanation: "ndNf" is the longest substring within "nndNfdfdf" that contains no repeated characters, and its length is 4 characters. Make the javascript function based on the following template. const solution = (s) => {};
const solution = (s) => { const m = new Map(); let max = 0; let start = 0; for (let i = 0; i < s.length; i++) { if (m.has(s[i])) { start = Math.max(start, m.get(s[i]) + 1); } m.set(s[i], i); max = Math.max(max, i - start + 1); } return max; };