Skip to content
BASA DSA

Longest Substring Without Repeating Characters

MediumSliding Window

Return the maximum length of a contiguous substring containing no repeated character.

Example 1

Input
s = "abba"
Output
2

Explanation

ab and ba are valid length-two windows; every longer window repeats a letter.

Example 2

Input
s = "pwwkew"
Output
3

Explanation

wke has length three; a subsequence does not qualify as a contiguous substring.

Example 3

Input
s = ""
Output
0

Explanation

An empty string has maximum window length zero.

Constraints

  • 0 <= len(s) <= 50000
  • s contains ASCII characters

Function contractlengthOfLongestSubstringArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…