Maximize credits with limited skips
AmazonSoftware Engineer · Online AssessmentLast updated
This question evaluates algorithm design and optimization skills in resource allocation under constraints, focusing on decision-making to maximize credits when turn-taking and limited skips affect processing.
You are given n warehouses with inventories inventory[0..n-1], and two dispatch amounts: you dispatch dispatch1 units first each turn, then your co-worker dispatches dispatch2 units. Your co-worker may skip their turn a total of at most skips times across all warehouses; when they skip, you immediately take the next dispatch instead. For a warehouse i, a credit is earned only if the warehouse becomes empty (inventory[i] <= 0) immediately after your dispatch on that warehouse. Determine the maximum total number of credits achievable over all warehouses by optimally choosing when the co-worker skips. Return an integer. Constraints: 1 <= n <= 1e5; 1 <= inventory[i], dispatch1, dispatch2, skips <= 1e9. Describe the algorithm and its time and space complexity, and implement getMaximumCredits(inventory, dispatch1, dispatch2, skips).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.