Longest Substring Without Repeating Characters

T: O(n)
Feedback

Longest Substring Without Repeating Characters

End=-1 ('undefined'). Window [0..-1] length 0. Max so far: 0.
String (sliding window)
a
b
c
a
b
c
b
b
start=0 end=-1 → length = 0  |  maxLen = 0
Window
SpeedNormal (500ms)
Parameters

{ s: string }

Variables
start0
end-1
maxLen0
windowLen0
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]] + 1
6 lastSeen[s[end]] = end
7 maxLen = max(maxLen, end - start + 1) → 0 (current len = 0)
8return maxLen
Output
End=-1 ('undefined'). Window [0..-1] length 0. Max so far: 0.