Longest Substring Without Repeating Characters
Given a string s, find the length of the **longest substring** without repeating characters.
Examples
s = "abcabcbb"3s = "bbbbb"1s = "pwwkew"3Constraints
0 <= s.length <= 5 * 10^4s consists of English letters, digits, symbols and spaces
๐ก Hints
Hint 1
Use a sliding window with a Set to track characters in the current window.
Hint 2
Expand right. If duplicate found, shrink from left until no duplicate.
Hint 3
Track the maximum window size seen.
Algorithm Complexity
Official asymptotic Big-O runtime and auxiliary memory analysis
Sliding window with a Set. Expand right, shrink left on duplicates, track max window size.
Sliding window with two pointers scans each character at most twice (once upon enter, once upon exit).
A hash set or map stores at most min(n, m) characters, bounded by the character set size m.
๐ Real-World Use Cases
Finding the longest unique sequence of packet IDs in a data stream before a repeat occurs.
๐ Dry Run
Initialize: empty Set, left=0, maxLen=0. Trace 'abcabcbb'.