Find longest substring without repeating characters
TikTokMachine Learning Engineer · OnsiteLast 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
sthat have all unique characters.
Examples
s = "abcabcbb"→ output3(e.g., "abc")s = "bbbbb"→ output1(e.g., "b")s = "pwwkew"→ output3(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).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.