566. Maximum Number of Upgradable Servers

Given n data centers and the task is to upgrade their servers.

You are provided with four arrays:

  • count[i]: The number of servers in the i-th data center.
  • upgrade[i]: The cost of upgrading a single server in the i-th data center.
  • sell[i]: The money you get by selling a server in the i-th data center.
  • money[i]: The initial amount of money available for upgrading servers in the i-th data center.

Return an array, where for each data center, the corresponding element in answer represents the maximum number of servers that can be upgraded.

Example 1:

Input: count = [4, 3], upgrade = [3, 5], sell = [4, 2], money = [8, 9]

Output: [3, 2]

Explanation:

For the first data center, if we sell one server, we will have 8 + 4 = 12 units of money, and we can upgrade 3 servers (as the cost of upgrading is 3 per server).

For the second data center, if we sell one server, we will have 9 + 2 = 11 units of money, and we can upgrade 2 servers (as the cost of upgrading is 5 per server).

Example 2:

Input: count = [1], upgrade = [2], sell = [1], money = [1]

Output: [0]

Explanation:

For the first data center, you cannot upgrade any servers because even after selling one server, you do not have enough money to upgrade a single server.

Now Your Turn!

Pick the correct output for the given input

Input: count = [5, 6], upgrade = [3, 4], sell = [2, 3], money = [10, 8]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= count.length == upgrade.length == sell.length == money.length <= 10^5
  • 1 <= count[i], upgrade[i], sell[i], money[i] <= 10^5

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
vector<int> maxUpgrades(vector<int>& count, vector<int>& upgrade, vector<int>& sell, vector<int>& money) {
}
};
 
Test Case

Input:

Count
Money
Sell
Upgrade