Longest substring of "abcabcbb" with no repeated character. The window [l, r] always holds distinct characters. r moves one step at a time. When s[r] is already inside, l jumps to just past the earlier copy, so each edge moves only forward and the scan is O(n).
Longest substring without repeats over 8 characters.
r = 0, 'a'. Not in the window, so it simply joins. Window "a" of length 1, a new best.
Right 0 is a. Window from 0 to 0, length 1.
r = 1, 'b'. Not in the window, so it simply joins. Window "ab" of length 2, a new best.
Right 1 is b. Window from 0 to 1, length 2.
r = 2, 'c'. Not in the window, so it simply joins. Window "abc" of length 3, a new best.
Right 2 is c. Window from 0 to 2, length 3.
r = 3, 'a'. 'a' is already inside at index 0, so l jumps from 0 to 1, just past that copy. Window "bca" of length 3.
Right 3 is a. Window from 1 to 3, length 3.
r = 4, 'b'. 'b' is already inside at index 1, so l jumps from 1 to 2, just past that copy. Window "cab" of length 3.
Right 4 is b. Window from 2 to 4, length 3.
r = 5, 'c'. 'c' is already inside at index 2, so l jumps from 2 to 3, just past that copy. Window "abc" of length 3.
Right 5 is c. Window from 3 to 5, length 3.
r = 6, 'b'. 'b' is already inside at index 4, so l jumps from 3 to 5, just past that copy. Window "cb" of length 2.
Right 6 is b. Window from 5 to 6, length 2.
r = 7, 'b'. 'b' is already inside at index 6, so l jumps from 5 to 7, just past that copy. Window "b" of length 1.
Right 7 is b. Window from 7 to 7, length 1.
Longest run without a repeat: "abc", length 3. Both edges only ever moved right, so the whole scan touched each character at most twice: O(n).
Best length 3.