Minimum Cost to Purchase Servers
SDE II
Another purchaing servers problem for AMZ full-time - Find Max Num Of Servers
AWS delivers various computing machines tailored to their customers' deployment and processing requirements. One particular AWS user is looking to acquire some machines for hosting their service.
You are provided with details of n machines represented through two lists: power and price. Here, power is a theoretical integer scale indicating the machine’s computing strength, while price specifies the number of AWS credits needed to acquire the machine. For simplicity, each machine has a price value of either 1 or 2. Your task is to determine the least possible overall price to obtain a collection of machines such that the cumulative power is at least a given threshold target.
If no selection of machines can achieve a total power that meets or surpasses target, return -1.
Note: A machine can only be chosen once.
Complete the function minCostToPurchaseServers in the editor.
minCostToPurchaseServers has the following parameters:
- 1.
int[] power: a list of integers denoting the computational strength of the machines - 2.
int[] price: a list of integers indicating the cost of the machines - 3.
int target: the minimum required total computational strength
Returns
int: the least total cost to obtain machines, or -1 if it’s unachievable