Quick Overview

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.

Solve non-repeating show substring

Company: Netflix

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Question LeetCode 3. Longest Substring Without Repeating Characters – variant where the elements are show names instead of numbers. https://leetcode.com/problems/longest-substring-without-repeating-characters/description/

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.

Netflix logs the sequence of shows a user starts in one binge session as a list of show names. Find the length of the longest contiguous streak of shows in which no show name repeats. This is the classic "Longest Substring Without Repeating Characters" (LeetCode 3), but the elements are full show-name strings instead of single characters. Given an array `shows` of strings, return the length of the longest contiguous subarray that contains no duplicate show name. Example: shows = ["Stranger Things", "The Crown", "Stranger Things", "Wednesday", "Ozark"] The longest non-repeating streak is ["The Crown", "Stranger Things", "Wednesday", "Ozark"] (after the first "Stranger Things" is dropped), so the answer is 4. Use a sliding window with a hash map from show name to its most recent index so the scan runs in O(n).

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

  1. Slide a window [start, i]. Keep a hash map from each show name to the last index where you saw it.
  2. 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.
  3. After updating the window, record max(longest, i - start + 1). Always overwrite the show's stored index to the current i.

Loading coding console...