You get a string s. Find the longest run of consecutive characters in it where no character appears twice, and return that run's length.
A run must be contiguous: "abc" is a run of "xabcx", but "ac" is not.
The second b repeats, so the window restarts just after the first one: "cdbef" has five different characters.
The space counts as a character: "go " and "o g" both have length 3.
Constraints
0 <= s.length <= 10⁵s may hold English letters, digits, symbols and spaces.Keep a window [left, right] holding no repeated character, and remember the last index where you saw each character.
Picture a frame laid over s that only ever slides to the right. Its right edge takes in one new character at a time. Its left edge moves only when it must: when the new character is already inside the frame. The longest the frame ever gets, while holding no repeat, is the answer.
Time O(n)Space O(1)
The full walkthrough and code are part of Premium
5