Longest Substring Without Repeating Characters
Medium Sliding Window AI round
s is a string of printable ASCII characters.
Look at the stretches of s: runs of characters that sit next to each other. A stretch is clean when no character appears in it more than once.
Return the length of the longest clean stretch, or 0 if s is empty.
Example 1
Input: s = "quartzq"
Output: 6
Of the stretches with no repeated character, "uartzq", from position 1 to position 6, is the longest, at 6 characters. The "q" on each end cannot both be in a stretch.
Example 2
Input: s = "mmmm"
Output: 1
Example 3
Input: s = "pqrqpstu"
Output: 6
Constraints
0 ≤ s.length ≤ 10⁵sholds only printable ASCII characters, from the space to~
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Sliding Window
- Sliding Window MaximumAI round · Hard
- Minimum Window SubstringAI round · Hard
- Minimum Size Subarray SumAI round · Medium
- Longest Substring with At Most K Distinct CharactersMedium
- Longest Repeating Character ReplacementMedium