Maximize points with limited coworker skips
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: This question evaluates algorithmic problem-solving and optimization under sequential-turn constraints, testing competency in dynamic programming, combinatorial reasoning, and time/space complexity analysis.
Constraints
- 0 <= len(c)
- 0 <= c[i] (non-negative item counts; an already-empty warehouse yields no point)
- m >= 1 and n >= 1 (positive removal amounts)
- 0 <= k (total skip tokens shared across all warehouses)
Examples
Input: ([2, 4, 6, 2, 4, 7], 2, 3, 0)
Expected Output: 4
Explanation: With no skips you finish warehouses with 2, 6, 2, and 7 items yourself (e.g. 6: you 6->4, coworker ->1, you ->win), so 4 points.
Input: ([2, 4, 6, 2, 4, 7], 2, 3, 3)
Expected Output: 6
Explanation: The two warehouses with 4 items each need exactly 1 skip to steal; with k=3 you can afford both (1+1=2 <= 3) on top of the four free wins, for all 6 points.
Hints
- Each warehouse is independent except that all warehouses draw skip tokens from the same global budget k, and winning any warehouse is worth exactly +1 point. So first compute, per warehouse, the MINIMUM skips needed to win it, then greedily buy the cheapest wins until k runs out.
- For one warehouse, search over the turn sequence: on your turn you remove m; on the coworker's scheduled turn you either let them remove n (free) or spend one skip to remove m yourself. You only ever need to skip when letting the coworker play would let THEM empty the warehouse, but a Dijkstra/BFS over (remaining, whose-turn) minimizing skips captures every case cleanly.
- Be careful not to greedily return the first finishing move you find: a path that lets the coworker play once more can sometimes reach a win with FEWER skips. Only declare a win when you pop a remaining<=0 state from a min-skips priority queue, never inside the relaxation step.