Design a VM Manager
Design a VM manager class with methods to start a VM, stop a VM, and calculate a user's total expenditure across all their VMs. Billing is $2 per vCPU per hour, and each method should run in O(1) time.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late September, 2026
The main task was to design a **VM manager** with three methods: `start_vm` to create a VM and return a unique ID, `stop_vm` to stop it, and `calculate_expenditure` to return a user’s total cost across all their VMs. Billing was **$2 per vCPU per hour**, calculated from timestamps in seconds. Running VMs accrue cost until the query time; stopped VMs accrue cost only until they were stopped. The key challenge was making each call **O(1)** rather than summing over every VM. The design tracked each user’s cumulative spend, last update time, and total running vCPUs. Before starting or stopping a VM, it would account for elapsed cost, then update the running vCPU count.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.