Question

Given a string s, find the length of the longest substring without repeating characters.

This is a sliding_window question.

Idea

  • Define a set for O(1) look up
  • Iterate through the string (while r < len(s))
  • If our char at r is in seen, we want to remove our char at l from seen and increment it WHILE the duplicate char is still in our seen set
  • Otherwise, add s[r] to seen, increment r and compute new max

Solution