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.
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.