← Questions
Playlist with add, remove and shuffle
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Netflix's technical phone screen, last asked Jan 2026. It tests arrays, randomization and data structure design.
Implement a video playlist that supports adding a title, removing a title, and shuffling: playing titles in a uniformly random order. The playlist can grow large and changes while it is being used.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
add(title_id: str) -> booladds a title, returningFalseif it is already in the playlist. -
remove(title_id: str) -> boolremoves a title, returningFalseif it is absent. -
random_title() -> str | Nonereturns a title chosen uniformly at random. -
shuffle() -> list[str]returns all current titles in a uniformly random order.
Example
add("A") -> True
add("B") -> True
add("C") -> True
add("A") -> False
remove("B") -> True
remove("B") -> False
random_title() -> "A" or "C", each with probability 1/2
shuffle() -> ["A", "C"] or ["C", "A"], each with probability 1/2
Constraints
- Up to 10^6 titles;
add,removeandrandom_titlein averageO(1);shuffleinO(n).
Clarifying questions
- Can a title appear more than once?
- Should playback after a shuffle continue through the shuffled order, and what happens when a title is added or removed mid-shuffle?
- Must
shufflereturn a new list or reorder the playlist in place? - Is a seeded random source needed for tests?
What a strong answer covers
- An array of titles plus a hash map from title to its index; removal swaps the last element into the removed slot and pops, keeping
O(1). - Uniform
random_titleby a random index, and Fisher-Yates forshuffle, with why the naive "swap with any index" version is biased. - How additions and removals interact with an in-progress shuffled play order.
- Tests that check membership and, statistically, uniformity; deterministic tests through an injected random generator.
Follow-ups
- Play every title once in random order, then reshuffle, without repeating the last title at the boundary.
- Weighted random choice by a per-title score.
- Allow duplicates of the same title.
Where it's asked
- Netflix · Technical phone screen · Last asked Jan 202660 min · Coding, practical problem solving, or SQL and pipeline design, depending on the org
What it tests
arrays · randomization · data structure design
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
