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
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 5, 2026
Last updated
Aug 6, 2026
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