PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates understanding of data structures and algorithms for prioritized selection with stateful constraints, focusing on maintaining dynamic relevance scores and avoiding immediate repeats; it is categorized under Coding & Algorithms.

  • easy
  • Netflix
  • Coding & Algorithms
  • Machine Learning Engineer

Implement rotating homepage title selector

Company: Netflix

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

Implement an in-memory service that chooses which movie or show title to display on a user's homepage billboard. Each title has a relevance score for the current user. Higher-scored titles should generally be returned first, but the service should avoid returning the same title on two consecutive calls when another title is available. Support these APIs: - `upsertTitleScore(title_id: string, score: float)` - Insert a new title or update the score of an existing title. - `getTopTitle() -> string` - Return the title that should be shown now. Requirements: - Titles with higher scores should be preferred. - If there is more than one available title, avoid returning the same title on two consecutive `getTopTitle()` calls. - A title remains eligible after being returned and may be returned again later. - If the system contains only one title, it may be returned repeatedly. - `upsertTitleScore` may be called many times for the same `title_id`, and updates must take effect correctly. Design and implement the data structure and explain the time complexity of your operations.

Quick Answer: This question evaluates understanding of data structures and algorithms for prioritized selection with stateful constraints, focusing on maintaining dynamic relevance scores and avoiding immediate repeats; it is categorized under Coding & Algorithms.

Implement an in-memory billboard selector for a streaming homepage. You are given a sequence of operations that either upsert a title's relevance score or ask for the title that should be shown right now. Rules for choosing a title on each get operation: 1. Prefer higher scores. 2. If the highest-scored title is the same as the title returned by the previous get operation, and at least one other title exists, return the highest-scored different title instead. 3. A title remains eligible after being returned. 4. If the system contains only one title, it may be returned repeatedly. 5. If multiple eligible titles have the same score, return the lexicographically smallest title_id. 6. If no titles exist when get is called, return None. Write a function that processes all operations and returns the results of every get operation in order.

Constraints

  • 1 <= len(operations) <= 200000
  • title_id consists of printable non-empty strings with length <= 50
  • -10^9 <= score <= 10^9
  • There are no delete operations
  • Your solution should support many repeated updates to the same title efficiently

Examples

Input: [('upsert', 'movieA', 10.0), ('upsert', 'movieB', 9.0), ('get',), ('get',), ('get',), ('get',)]

Expected Output: ['movieA', 'movieB', 'movieA', 'movieB']

Explanation: movieA has the highest score, but once it is shown, movieB is chosen next to avoid repeating the same title consecutively.

Input: [('upsert', 'a', 5.0), ('upsert', 'b', 4.0), ('get',), ('upsert', 'b', 6.0), ('get',), ('get',), ('upsert', 'a', 7.0), ('get',), ('get',)]

Expected Output: ['a', 'b', 'a', 'b', 'a']

Explanation: Updates immediately change the ordering. Even after a title becomes highest-scored, it is skipped if it was also the previous answer and another title exists.

Input: [('upsert', 'solo', 3.5), ('get',), ('get',), ('upsert', 'solo', 8.0), ('get',)]

Expected Output: ['solo', 'solo', 'solo']

Explanation: With only one title in the system, it may be returned on consecutive calls.

Input: [('upsert', 'beta', 5.0), ('upsert', 'alpha', 5.0), ('get',), ('get',), ('get',)]

Expected Output: ['alpha', 'beta', 'alpha']

Explanation: The scores are tied, so the lexicographically smaller title_id is preferred among eligible titles.

Input: [('get',), ('upsert', 'x', -1.0), ('get',)]

Expected Output: [None, 'x']

Explanation: A get on an empty system returns None. Negative scores are still valid and can be returned if they are the only title.

Input: [('upsert', 'a', 10.0), ('upsert', 'a', 1.0), ('upsert', 'b', 5.0), ('get',), ('get',)]

Expected Output: ['b', 'a']

Explanation: The old score 10.0 for title 'a' must be ignored after it is updated to 1.0. Then 'b' is top, followed by 'a' on the next call to avoid repeating 'b'.

Hints

  1. You only need the best title, and sometimes the second-best title. A max-heap plus the previously returned title is a good starting point.
  2. Updates can leave old heap entries behind. Consider lazy deletion with version numbers so outdated scores are ignored.
Last updated: May 8, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Cache, Undo, and DFS - Netflix
  • Implement Streaming Word Counter - Netflix (medium)
  • Implement TTL Cache and Tree Balance Reporting - Netflix (medium)
  • Implement ordering and undo executor - Netflix (medium)
  • Implement Caches, Undo, and Traversal - Netflix