Longest Substring Without Repeating Characters
Medium Sliding Window
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~
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
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.
See the AI roundWatch the explanation
More Sliding Window
- Sliding Window MaximumAI round · Hard
- Minimum Window SubstringAI round · Hard
- Minimum Size Subarray SumAI round · Medium
- Longest Repeating Character ReplacementAI round · Medium
- Longest Substring with At Most K Distinct CharactersMedium