CodePark/ problems / Longest Substring Without Repeats
START PRACTICINGPRACTICE
Coding problem · Data structures and algorithms › Sliding window

Longest Substring Without Repeats

mediumabout 20 minutes in an interview

Find the longest stretch of s that has no repeated character, and return its length. A stretch here means a substring: characters that sit side by side in s.

  • s may hold any single characters: letters, digits, spaces, punctuation and so on.
  • Upper and lower case are different characters, so "a" and "A" don't clash.
  • An empty string gives 0.
  • s can be up to 100,000 characters long, and the answer can be long too.
Input: s = "abacdb" Output: 4"bacd" and "acdb" both have 4 different characters.
Input: s = "zzzz" Output: 1
Input: s = "abba" Output: 2