Back to DSA

Longest Substring Without Repeating Characters

medium
Acceptance: 42%
StringsSliding Window

Given a string, determine the length of its longest contiguous segment that contains no repeated characters. Every character in the segment must be distinct.

Examples

Example 1:
Input:s = "xyzxyzaa"
Output:3
Explanation: The segment 'xyz' has length 3 and contains all unique characters. No longer valid segment exists.
Example 2:
Input:s = "qqqqq"
Output:1
Explanation: Every character is identical, so the longest segment without repetition has length 1.

Hints

00:00
1234567