[ INFO ]category: Coding difficulty: medium freq: medium first seen: 2026-01-13
[MEDIUM][CODING][MEDIUM]Hash TableDesignOOP
$catproblem.md
Design and implement a simple in-memory virtual-machine (VM) manager that supports CRUD operations on VMs. Each VM is identified by a unique string id and has a collection of string key/value attributes (e.g., "cpu":"4", "ram":"8G", "os":"ubuntu-20.04"). Your manager must expose four operations:
create(vm_id, attributes) – create a new VM with the given id and attributes. If a VM with that id already exists, raise an exception.
delete(vm_id) – remove the VM with the given id. If no such VM exists, raise an exception.
update(vm_id, new_attributes) – merge new_attributes into the existing attributes of the VM. If a key in new_attributes already exists, overwrite it; if it does not exist, add it. If no VM with the given id exists, raise an exception.
get(vm_id) – return a dictionary containing a copy of the attributes of the VM. If no VM with the given id exists, raise an exception.
All returned data must be defensive copies so that callers cannot modify the internal state of the manager. Implement the manager as a class with these four public methods.