Simple VM manager with add, list, modify and delete
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Nvidia's technical phone screen, last asked Nov 2025. It tests object-oriented design, crud and error handling.
Write a simple in-memory manager for virtual machines that can create, list, update and delete VMs. Each VM has an id (unique), name, cpu_cores, memory_gb and status (for example "running" or "stopped"). Errors must be detected and returned in one consistent way, and the code should be easy to extend.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
create_vm(vm: dict) -> stradds a VM; returns"created", or"error: duplicate id"if the id exists. -
list_vms() -> list[dict]returns copies of all VMs sorted byid. -
update_vm(id: int, fields: dict) -> strchanges the given fields; returns"updated", or"error: not found". -
delete_vm(id: int) -> strreturns"deleted", or"error: not found".
Example
create_vm({"id": 2, "name": "db", "cpu_cores": 4, "memory_gb": 16, "status": "running"}) -> "created"
create_vm({"id": 1, "name": "web", "cpu_cores": 2, "memory_gb": 8, "status": "stopped"}) -> "created"
create_vm({"id": 1, "name": "dup", "cpu_cores": 2, "memory_gb": 4, "status": "stopped"}) -> "error: duplicate id"
update_vm(1, {"status": "running", "memory_gb": 12}) -> "updated"
update_vm(3, {"status": "stopped"}) -> "error: not found"
delete_vm(2) -> "deleted"
list_vms() -> [{"id": 1, "name": "web", "cpu_cores": 2, "memory_gb": 12, "status": "running"}]
Constraints
- Up to 10^4 operations; ids are integers.
-
update_vmnever changes theid.
Clarifying questions
- Should errors be exceptions, error codes or return values?
- Should
list_vmshave a fixed order? - Should
update_vmvalidate field names and values (negative cores, unknown status)? - Is thread safety needed?
What a strong answer covers
- A dictionary keyed by id for average
O(1)create, update and delete, and sorting (or an ordered map) for deterministic listing. - Returning copies so callers cannot mutate stored VMs behind the manager's back.
- One consistent error style across all methods, and validation of inputs.
- A structure that extends easily: a
VMdataclass, a separate storage layer, room for new attributes and operations such as start and stop. - Tests for duplicates, missing ids, and update of several fields at once.
Follow-ups
- Add
start_vmandstop_vmwith valid state transitions only. - Make the manager safe for concurrent callers.
- Persist the VMs so they survive a restart.
- Add filtering, such as all running VMs with at least 8 GB.
Where it's asked
- Nvidia · Technical phone screen · Last asked Nov 2025Live technical interview, 45 to 90 minutes; a project discussion, then a small task
What it tests
object-oriented design · crud · error handling
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
