{ s: string }
1start = 0, maxLen = 0 (n = 8)2lastSeen = {}3for end = 0 to n-1:4 if s[end] in lastSeen and lastSeen[s[end]] >= start:5 start = lastSeen[s[end]] + 16 lastSeen[s[end]] = end7 maxLen = max(maxLen, end - start + 1) → 0 (current len = 0)8return maxLen
1function lengthOfLongestSubstring(s: string): number {2 let start = 0, maxLen = 0;3 const lastSeen: Record<string, number> = {};4 for (let end = 0; end < s.length; end++) {5 if (s[end] in lastSeen && lastSeen[s[end]] >= start)6 start = lastSeen[s[end]] + 1;7 lastSeen[s[end]] = end;8 maxLen = Math.max(maxLen, end - start + 1);9 }10 return maxLen;11}