/3. Longest Substring Without Repeating Characters

3. Longest Substring Without Repeating Characters

Medium
Hash Table38.6% acceptance

Given a string input_string, determine the maximum length of any contiguous substring in input_string that contains only unique characters (no character repeats within the substring). Return this maximum length as an integer.

Example 1

Input: "xyzxyzz"

Output: 3

Explanation: The longest substring with unique characters is xyz or yzx, length 3.

Example 2

Input: "aaaa"

Output: 1

Explanation: The longest substring with unique characters is a, length 1.

Example 3

Input: "123456123"

Output: 6

Explanation: The longest substring with unique characters is 123456, length 6.

Constraints

  • 0 <= len(input_string) <= 50000
  • input_string consists of English letters, digits, symbols, and spaces
Python (current runtime)

Case 1

Input: "abcbdeaf"

Expected: 5

Case 2

Input: ""

Expected: 0

Case 3

Input: "a b c d e f"

Expected: 7

Case 4

Input: "xyxxyx"

Expected: 2

Case 5

Input: "!@#$$%^&*()"

Expected: 8