Back
Sliding Window
Question 1 of 10
10% Complete
Medium
Complete the variable sliding-window for longest substring without repeating characters
Maintain a window with a map from char to last index; shrink on repeats.
def
lengthOfLongestSubstring
(s: str) -> int:
last = {}
left =
0
best =
0
for
right, ch
in
enumerate
(s):
if
ch
in
last
and
:
return
best
Submit All Answers
Need a hint?
When a repeat appears inside the window, move left just past its last occurrence.