Longest Substring Without Repeats
MediumPractice library · +20 XPsliding windowhash mapstrings
Given a string s, find the length of the longest contiguous substring in which no character appears twice.
Input
One line: the string s (lowercase letters and digits).
Output
One integer: the length.
Constraints
- 1 <= |s| <= 200000
scontains onlya-zand0-9
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
abcabcbb
Output
3
The answer is "abc", length 3.
Example 2
Input
bbbbb
Output
1
Hints
Similar problems
- Longest Substring With At Most K Distinct CharactersMedium
- String with Most Unique CharactersMedium
- Longest Prefix With No RepeatsMedium
- Longest Alternating SubstringMedium
- Count Subarrays with Distinct ElementsMedium
- Distinct Elements in Sliding WindowMedium
More topics: Strings problems, Hash Map and Hashing problems, Sliding Window problems
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
abcabcbb
Example 2 input
bbbbb