Katkat

Find longest substring without repeating characters

TikTokMachine Learning Engineer · Onsite

Last updated

This question evaluates proficiency in string processing, duplicate-detection using appropriate data structures, and algorithmic complexity analysis within the Coding & Algorithms domain.

Problem

Given a string s, find the length of the longest contiguous substring that contains no repeated characters.

Input

  • A string s (may contain letters, digits, symbols, and spaces).

Output

  • An integer: the maximum length among all substrings of s that have all unique characters.

Examples

  1. s = "abcabcbb" → output 3 (e.g., "abc")
  2. s = "bbbbb" → output 1 (e.g., "b")
  3. s = "pwwkew" → output 3 (e.g., "wke")

Constraints (typical interview assumptions)

  • 0 ≤ len(s) ≤ 10^5
  • Aim for an algorithm faster than O(n^2).

Notes

  • Substring must be contiguous (not a subsequence).