Find longest unique show window
Company: Netflix
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates concepts in sliding-window algorithms, hash-based duplicate tracking, case-insensitive string handling, and the extension of batch solutions to streaming (online) inputs.
Part 1: Longest Unique Show Window
Constraints
- 0 <= len(shows) <= 200000
- Each element of shows is a string
- Comparison is case-insensitive
- Use 0-based indexing
- The end index in the answer is inclusive
Examples
Input: ["Friends", "Seinfeld", "The Office", "friends", "Lost"]
Expected Output: (1, 4)
Explanation: The longest case-insensitive unique window is ["Seinfeld", "The Office", "friends", "Lost"], from index 1 to 4.
Input: ["A", "B", "a", "b"]
Expected Output: (0, 1)
Explanation: Several longest windows have length 2: [0,1], [1,2], and [2,3]. Return the earliest start index.
Input: ["A", "b", "C"]
Expected Output: (0, 2)
Explanation: All show names are distinct ignoring case, so the whole array is the answer.
Input: []
Expected Output: (-1, -1)
Explanation: Empty input has no valid window.
Input: ["Only"]
Expected Output: (0, 0)
Explanation: A single element forms a valid window of length 1.
Hints
- Try using a sliding window with two pointers.
- Store the most recent index of each normalized show name so you can move the left side of the window in O(1).
Part 2: Streaming Longest Unique Show Window Reports
Constraints
- 0 <= len(shows) <= 200000
- Each element of shows is a string
- Comparison is case-insensitive
- Use 0-based indexing
- The end index in each reported tuple is inclusive
Examples
Input: ["A", "B", "a", "C"]
Expected Output: [(0, 0), (0, 1), (0, 1), (1, 3)]
Explanation: After the third show, the current unique suffix is [1,2], but the best-so-far window is still [0,1]. After the fourth show, [1,3] becomes the new best.
Input: ["Ted", "Dexter", "Office", "ted", "Lost"]
Expected Output: [(0, 0), (0, 1), (0, 2), (0, 2), (1, 4)]
Explanation: The repeat of "Ted" forces the current window to start at index 1, and adding "Lost" then creates a longer best window [1,4].
Input: ["x", "X", "x"]
Expected Output: [(0, 0), (0, 0), (0, 0)]
Explanation: All arrivals are the same show ignoring case, so the best window never exceeds length 1.
Input: []
Expected Output: []
Explanation: No arrivals means no reports.
Input: ["Solo"]
Expected Output: [(0, 0)]
Explanation: After one arrival, the longest valid window is that single element.
Hints
- You only need to know the current unique suffix ending at the newest item, plus the best window seen so far.
- A hash map from normalized show name to its latest index lets you update the left boundary quickly when a duplicate arrives.