Solve non-repeating show substring
Company: Netflix
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of sequence processing, uniqueness detection, and the use of auxiliary data structures to track previously seen elements when finding non-repeating contiguous subsequences, applied to show names instead of characters.
Constraints
- 0 <= shows.length <= 5 * 10^4
- Each show name is a non-empty string; names are compared for exact equality (case-sensitive).
- The answer is the COUNT of shows in the longest window, not the window's contents.
- An empty input returns 0.
Examples
Input: (["Stranger Things", "The Crown", "Stranger Things", "Wednesday", "Ozark"],)
Expected Output: 4
Explanation: The window restarts after the repeated "Stranger Things"; the streak ["The Crown", "Stranger Things", "Wednesday", "Ozark"] has 4 distinct shows.
Input: (["Friends", "Friends", "Friends"],)
Expected Output: 1
Explanation: Every show is the same, so the longest distinct streak is a single show.
Input: (["Narcos", "Dark", "Mindhunter", "Sense8"],)
Expected Output: 4
Explanation: All four shows are distinct, so the entire list is one non-repeating streak.
Input: ([],)
Expected Output: 0
Explanation: No shows watched, so the longest streak length is 0.
Input: (["You"],)
Expected Output: 1
Explanation: A single show is trivially a non-repeating streak of length 1.
Input: (["A", "B", "A", "B", "C", "D", "B"],)
Expected Output: 4
Explanation: The window ["A", "B", "C", "D"] starting at the second "A" gives 4 distinct shows before "B" repeats.
Input: (["Lupin", "Money Heist", "Lupin", "Lupin", "Money Heist"],)
Expected Output: 2
Explanation: Consecutive repeats keep collapsing the window; the best is two distinct shows like ["Lupin", "Money Heist"].
Hints
- Slide a window [start, i]. Keep a hash map from each show name to the last index where you saw it.
- When you encounter a show already inside the current window (its stored index >= start), jump start to one past that previous occurrence instead of shrinking one step at a time.
- After updating the window, record max(longest, i - start + 1). Always overwrite the show's stored index to the current i.