Longest Substring Without Repeating Characters
Given a string s, find the length of the longest substring without repeating characters.
A substring is a contiguous sequence of characters within a string.
Example 1
Input
abcabcbb
Output
3
Explanation
The longest substring without repeating characters is "abc", which has a length of 3.
Example 2
Input
bbbbb
Output
1
Explanation
The longest substring without repeating characters is "b", which has a length of 1.
Constraints
Hints:
Hint 1
Use a sliding window to maintain a substring with unique characters.
Hint 2
Store the last seen index of each character in a hash map. When a duplicate character is encountered inside the current window, move the left pointer to one position after its previous occurrence.
Author & Technical Reviewer
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output