Implement a cache that evicts its heaviest entries first

Quick Overview

Implement a cache with a total-weight budget and heaviest-first eviction. Handle key updates, stale priorities, tie rules, incoming-entry policy, and the time and memory trade-offs of lazy versus indexed heaps.

Implement a cache that evicts its heaviest entries first

Company: Netflix

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

Implement a weighted cache with a limit on total stored weight. When an insertion or update makes the total exceed the limit, evict the entry with greatest weight first and continue until the total is within the limit. Handle updates to existing keys and operations that require multiple evictions. Explain the time and space costs. ```hint Separate old and new versions An update changes both total weight and the entry's eviction priority. Any retained priority record must identify which version of the entry it describes. ``` ### Clarifying Questions - Are weights positive integers, and what should happen if one entry exceeds the whole capacity? - How should equal-weight entries be ordered for eviction? - May the newly inserted or updated entry itself be evicted? - Should a missing lookup raise an error or return a sentinel? ### What a Strong Answer Covers - Correct total-weight accounting on insertion and update - Maximum-weight eviction repeated until capacity is satisfied - Stale priority records or an alternative updateable ordering structure - Complexity, memory growth, and explicit edge-case behavior ### Follow-up Questions - How would repeated updates to one key affect a lazy priority queue's memory use? - What would an indexed heap change about worst-case update and eviction costs? - How would concurrent updates preserve the weight invariant?

Overview: Implement a cache with a total-weight budget and heaviest-first eviction. Handle key updates, stale priorities, tie rules, incoming-entry policy, and the time and memory trade-offs of lazy versus indexed heaps.

Netflix logo
Netflix
Nov 29, 2026
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
0
0

Implement a weighted cache with a limit on total stored weight. When an insertion or update makes the total exceed the limit, evict the entry with greatest weight first and continue until the total is within the limit. Handle updates to existing keys and operations that require multiple evictions. Explain the time and space costs.

Clarifying Questions Guidance

  • Are weights positive integers, and what should happen if one entry exceeds the whole capacity?
  • How should equal-weight entries be ordered for eviction?
  • May the newly inserted or updated entry itself be evicted?
  • Should a missing lookup raise an error or return a sentinel?

What a Strong Answer Covers Guidance

  • Correct total-weight accounting on insertion and update
  • Maximum-weight eviction repeated until capacity is satisfied
  • Stale priority records or an alternative updateable ordering structure
  • Complexity, memory growth, and explicit edge-case behavior

Follow-up Questions Guidance

  • How would repeated updates to one key affect a lazy priority queue's memory use?
  • What would an indexed heap change about worst-case update and eviction costs?
  • How would concurrent updates preserve the weight invariant?