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.
Design and implement an in-memory disk space manager that stores datasets by datasetId with a given size (e.g., in MB). The manager has a fixed total capacity (total space), not a limit on the number of datasets.
You must support:
put(datasetId, size)
size > totalCapacity
, return an error (the dataset can never fit).
get(datasetId)
size
for that dataset if present; otherwise indicate “not found”.
Clarify/handle updates: if put is called for an existing datasetId, treat it as replacing the old size (adjust used space accordingly).
Implement the class/API in the language of your choice (e.g., Java).