← 返回 netflix 的题目列表Variant of Longest Substring Without Repeating Characters (string version, multiple follow-ups)
类型:online_judge
Problem
Given a string s, implement a function to compute the length (or return the substring itself, as required) of the longest contiguous substring that satisfies certain uniqueness constraints.
This is a variant of LeetCode 3 and came with multiple follow-ups in the interview.
Base version
Find the longest substring where all characters are distinct.
Variants / follow-ups (as described verbally)
Generalize the constraint from “no repeated characters” to “unique name/identifier” (an array-version rephrased into a string-version).
Another follow-up mentioned: find the longest contiguous subarray/substring with unique names.
Note: The original interview note does not provide the full formal statement of each variant, so this summarizes the question family as “longest window under a uniqueness constraint”.
I/O
Input: a string s
Output: length of the longest valid substring (or the substring itself)
Constraints
1 <= len(s) <= 2e5 (typical interview scale; aim for O(n) or near O(n))
Examples
Input: abcabcbb -> Output: 3
Input: bbbbb -> Output: 1
Input: pwwkew -> Output: 3
Sample tests (5)
abcabcbb -> 3
bbbbb -> 1
pwwkew -> 3
(empty string) -> 0
dvdf -> 3
Example
Input
abcabcbb
Output
3