|Longest Unique Substring
All Challenges

Longest Unique Substring

HardStrings

Given a string s, return the length of the longest substring that contains no repeating characters.


A substring is a contiguous sequence of characters within the string.


This is the classic sliding window problem. Real-world uses: stream deduplication, session token validation, and compression algorithms.

Examples

Input: length_of_longest_substring("abcabcbb")
Output: 3
"abc" — length 3
Input: length_of_longest_substring("bbbbb")
Output: 1
"b" — only one unique char
Input: length_of_longest_substring("pwwkew")
Output: 3
"wke" — length 3
Input: length_of_longest_substring("")
Output: 0
Empty string

Constraints

  • 0 <= len(s) <= 50,000
  • s may contain letters, digits, symbols, and spaces
pythoneditor
Loading Python runtime…