Find the Longest Substring without Repeated Characters
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Find the longest nonrepeating substring with a sliding window and last-seen positions. Prove why the left boundary must never move backward and account for empty input and character representation.
Constraints
- text is a string of characters; the source gives no length bound or encoding restriction.
- A substring is contiguous and each of its characters must be distinct.
- Equality is exact and no normalization is applied.
- Return 0 for the empty string.
Examples
Input: ('',)
Expected Output: 0
Explanation: There is no nonempty substring.
Input: ('a',)
Expected Output: 1
Explanation: The one character is distinct.
Hints
- A substring with no repeated character may start or end anywhere in the text.
- The result is a length, so equal-length substrings produce the same answer.