Longest Substring of Unique Characters

Longest Substring of Unique Characters

Given a string, find the length of the longest substring without repeating characters.

example

Input: String (str).

Output: Integer (int).

Examples:

assert longest_substr("abcabcbb") == 3
assert longest_substr("bbbbb") == 1
assert longest_substr("pwwkew") == 3
assert longest_substr("abcdef") == 6

How it’s used:

  • data validation for passwords to ensure the inclusion of a sufficiently long sequence of non-repeated characters;
  • text analysis, especially for cryptography and coding patterns;
  • identifying unique patterns in a sequence.