Design Gurus Logo
Longest Substring Without Repeating Characters (medium)

Problem Statement

Given a string, identify the length of its longest segment that contains distinct characters. In other words, find the maximum length of a substring that has no repeating characters.

Examples:

  1. Example 1:

    • Input: "abcdaef"
    • Expected Output: 6
    • Justification: The longest segment with distinct characters is "bcdaef", which has a length of 6.
  2. Example 2:

    • Input: "aaaaa"
    • Expected Output: 1
    • Justification: The entire string consists of the same character. Thus, the longest segment with unique characters is just "a", with a length of 1.
  3. Example 3:

    • Input: "abrkaabcdefghijjxxx"
    • Expected Output: 10
    • Justification: The longest segment with distinct characters is "abcdefghij", which has a length of 10.

Constraints:

  • 0 <= s.length <= 5 * 10<sup>4</sup>
  • s consists of English letters, digits, symbols and spaces.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory