Weighted-Capacity Cache with a Time-to-Live Follow-up

Asked at Netflix · Coding Questions · Difficulty: Medium · Last asked May 12, 2026

Build an in-memory cache where every item has a weight (for example its size in bytes) and the cache holds at most a fixed total weight. When an insert pushes the total over the limit, the cache evicts its heaviest items first, so one large item frees the most room. A follow-up asks for a second cache whose items expire after a fixed time.

Loading the problem…