Dedupe titles in per-shelf viewport
Company: Netflix
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithmic problem-solving and state management for streaming deduplication with order preservation, testing competencies in data structures, deterministic filtering, and handling constrained visibility windows.
Constraints
- 0 <= X <= 10^5
- 0 <= number of shelves <= 10^5 (practical limits depend on total titles)
- 0 <= total number of title IDs across all shelves <= 2 * 10^5
- titleId values fit in 32-bit signed integers
- Must preserve relative order of remaining titles within each shelf
Examples
Input: ([[1, 2, 1, 3], [2, 4, 2, 5]], 2)
Expected Output: [[1, 2, 3], [4, 2, 5]]
Explanation: Shelf1 viewport window indices 0..1 outputs 1,2 => globally visible {1,2}. Later in shelf1, only local dedupe applies so 3 is kept. Shelf2 index0=2 is globally visible so skipped; index1=4 kept and becomes globally visible; index2=2 is beyond viewport window so global dedupe no longer applies and 2 can be output (locally unique).
Input: ([[1, 1, 2, 1], [1, 3, 1, 4]], 2)
Expected Output: [[1, 2], [3, 1, 4]]
Explanation: Shelf1 viewport window [1,1] outputs only one 1 (local dedupe), making {1} globally visible; later 2 is kept. Shelf2 viewport index0=1 skipped globally; index1=3 kept (global add 3); beyond viewport, 1 is allowed and then 4.
Input: ([[1, 2], [2, 3, 2]], 3)
Expected Output: [[1, 2], [3]]
Explanation: Shelf1 outputs 1,2 in its (short) viewport window, so {1,2} globally visible. Shelf2's entire list is within its viewport window (X=3): 2 is skipped globally, 3 kept, last 2 skipped globally again.
Input: ([[1, 2, 1], [1, 3, 1]], 1)
Expected Output: [[1, 2], [3, 1]]
Explanation: Only index0 of each shelf is in the viewport window. Shelf1 index0=1 becomes globally visible; later 2 is kept (local dedupe). Shelf2 index0=1 skipped globally; index1=3 kept; index2=1 is beyond viewport so allowed (and locally unique).
Input: ([[1, 1, 2], [2, 2, 1]], 0)
Expected Output: [[1, 2], [2, 1]]
Explanation: With X=0, no items are in the viewport window, so global dedupe never applies; only per-shelf local dedupe is performed.