FastPrepFastPrep
Problem Brief

VM Rental Revenue

INTERNOA

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.

1Example 1

Input
vmStock = [1, 2, 4], customerRequests = 4
Output
15
Explanation

The rental costs are 5, 4, 3, and 3, for a total revenue of 15.

Constraints

Limits and guarantees your solution can rely on.

  • Stocks are non-negative integers.
  • The number of requests may be as large as the total available stock.
public long calculateVmRentalRevenue(int[] vmStock, int customerRequests) {
  // write your code here
}
Input

vmStock

[1, 2, 4]

customerRequests

4

Output

15

Sign in to submit your solution.