679. Maximum Robots Within Budget

HardStackDequeSliding Window

You have n robots; the cost of running a consecutive group is max(chargeTimes in the group) + (group length) * sum(runningCosts in the group). Given chargeTimes, runningCosts, and a budget, return the maximum number of consecutive robots you can run without exceeding the budget. The input is JSON {chargeTimes, runningCosts, budget}.

Input: JSON {chargeTimes, runningCosts, budget}.

Output: Integer — the maximum consecutive robots.

Examples

Example 1
Input: {"chargeTimes":[3,6,1,3,4],"runningCosts":[2,1,3,4,5],"budget":25}
Output: 3
Explanation: Robots at indices 0-2 cost at most 25.
Example 2
Input: {"chargeTimes":[11,12,19],"runningCosts":[10,8,7],"budget":19}
Output: 0
Explanation: No single robot fits the budget.
Example 3
Input: {"chargeTimes":[5],"runningCosts":[2],"budget":10}
Output: 1
Explanation: One robot fits.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →