There are multiple VM types, each with an initial stock count. A sequence of customers rent one VM at a time.
Each customer always rents from the VM type with the highest remaining stock. The revenue from a rental equals the sum of the current highest stock and the current lowest non-zero stock across all VM types. After the rental, the chosen VM type loses one unit of stock.
Return the total revenue after serving customerRequests customers.
Examples
01 · Example 1
vmStock = [1, 2, 4] customerRequests = 4 return = 15
The rental costs are 5, 4, 3, and 3, for a total revenue of 15.
Constraints
- Stocks are non-negative integers.
- The number of requests may be as large as the total available stock.
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public long calculateVmRentalRevenue(int[] vmStock, int customerRequests) {
// write your code here
}
vmStock[1, 2, 4]
customerRequests4
expected15
sign in to submit