← Questions

Playlist with add, remove and shuffle

0
NetflixCodingLast asked Jan 2026

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) -> bool adds a title, returning False if it is already in the playlist.
  • remove(title_id: str) -> bool removes a title, returning False if it is absent.
  • random_title() -> str | None returns 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, remove and random_title in average O(1); shuffle in O(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 shuffle return 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_title by a random index, and Fisher-Yates for shuffle, 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

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