Minimum Cost to Purchase Servers
Learn this problemProblem statement
AWS provides a range of servers to meet their clients' deployment and computation needs. One AWS client wants to purchase servers to deploy their application.
You are given a description of n servers in the form of two arrays, efficiency and cost. Here efficiency is a hypothetical integer metric that represents the computational power of the server, and cost is the number of AWS credits required to purchase the server. For simplicity, the servers have cost = 1 or cost = 2. Find the minimum possible total cost to purchase a set of servers with the total sum of efficiency greater than or equal to a given integer k.
If it is not possible to get a total efficiency of greater than or equal to k, report -1 as the answer.
Note: A server can only be purchased once.
Function
minCostToPurchaseServers(power: int[], cost: int[], target: int) → intComplete the function minCostToPurchaseServers.
minCostToPurchaseServers has the following parameters:
int[] efficiency: an array of integers representing the computational power of the serversint[] cost: an array of integers representing the cost of the serversint k: the minimum total efficiency required
Returns
int: the minimum total cost to purchase the servers, or -1 if it is not possible.
Examples
Example 1
power = [4, 4, 6, 7]cost = [1, 1, 2, 2]target = 7return = 2Constraints
- Each server's
costis either1or2. - Each server can be purchased at most once.
- If no selection of servers achieves a total efficiency greater than or equal to
k, the answer is-1.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026