Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Given a string s, find the length of the longest substring that contains no repeating characters. A substring is a contiguous sequence of characters within the string. Example: s="abcabcbb" → 3 (substring "abc") Example: s="bbbbb" → 1 (substring "b") Example: s="pwwkew" → 3 (substring "wke")
Input format — only if your code reads from stdin
Input format: - A single string s Output: a single integer — the length of the longest substring without repeating characters.
Approach
Sliding window with a hash map: maintain a window [left, right]. Advance right pointer; if s[right] is already in the window, move left pointer past the previous occurrence. Track the maximum window size at each step.
Input
Output
- •
0 ≤ len(s) ≤ 5×10^4, s consists of English letters, digits, symbols, and spaces
More Strings problems
Browse all coding problems →Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards