Implement a disk space manager with eviction
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of in-memory resource management, capacity accounting, eviction policies, and data-structure design for efficient dataset lookup and size tracking in the Coding & Algorithms domain.
Constraints
- 0 <= total_capacity <= 10^9
- 0 <= len(operations) <= 2 * 10^5
- For each put operation, 1 <= size <= 10^9
- datasetId is a non-empty string
- Use LRU eviction: successful get and successful put/update make the dataset most recently used
Examples
Input: (5, [])
Expected Output: []
Explanation: No operations means no output.
Input: (10, [('put', 'A', 4), ('put', 'B', 3), ('get', 'A'), ('put', 'C', 5), ('get', 'B'), ('get', 'A'), ('get', 'C')])
Expected Output: ['ok', 'ok', 4, 'ok', -1, 4, 5]
Explanation: After get('A'), A becomes most recent. Putting C needs 5 units, so B is evicted first as the least recently used dataset.
Hints
- You need two things at once: fast lookup by datasetId and fast access to the least recently used dataset.
- When updating an existing dataset, free its old size before deciding whether you still need to evict other datasets.