Amazon Interview Question

Problem Statement: Amazon EC2 VM Rental Revenue In Amazon EC2, there are n types of virtual machines (VMs), each with a specific number of instances available (represented by the array vmStock). When a customer rents a VM, the price they pay is calculated based on the current availability across all VM types. Revenue Calculation For every rental, the fee is the sum of: 1. The highest availability currently existing among all VM types. 2. The lowest non-zero availability currently existing among all VM types. Rental Rules • There are m customers arriving one after another. • A customer always rents from the VM type that currently has the highest availability. • After a rental occurs, the availability of that specific VM type decreases by 1. Goal Calculate the total revenue earned after all m customer requests have been served. Example Input: • n = 3 • vmStock = [1, 2, 4] • m = 4