Compute Remaining GPUs With Switching Limits
Company: Mistral AI
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to perform time-series aggregation, array manipulation, and constrained optimization for selecting resources across multiple clusters and days.
Part 1: Daily Remaining GPUs by Cluster
Constraints
- 0 <= num_days <= 10000
- 0 <= len(capacities) <= 200
- 0 <= len(usages) <= 200000
- 0 <= gpu_used
- For every day and cluster, total gpu_used does not exceed that cluster's capacity
Examples
Input: ([10, 20], 3, [(2, 0, 2), (0, 1, 13), (1, 1, 8), (2, 1, 2), (0, 0, 5)])
Expected Output: [[5, 7], [10, 12], [8, 18]]
Explanation: Usages are unsorted. Day 0 leaves [5, 7], day 1 leaves [10, 12], and day 2 leaves [8, 18].
Input: ([4, 6], 2, [])
Expected Output: [[4, 6], [4, 6]]
Explanation: No usage happens on any day, so every day ends with full capacity.
Input: ([8, 8], 2, [(0, 0, 3), (0, 0, 2), (0, 1, 1), (1, 1, 8)])
Expected Output: [[3, 7], [8, 0]]
Explanation: Day 0 cluster 0 has two usage records, so 3 + 2 GPUs are consumed there.
Input: ([3, 4], 0, [])
Expected Output: []
Explanation: There are no days to report.
Hints
- Because clusters reset every day, start each day with a fresh copy of capacities.
- If the same day and cluster appear multiple times, subtract all of them from that day's starting capacity.
Part 2: Maximum Usable GPUs with Unlimited Switching
Constraints
- 0 <= num_days <= 10000
- 0 <= len(capacities) <= 200
- 0 <= len(usages) <= 200000
- 0 <= gpu_used
- For every day and cluster, total gpu_used does not exceed that cluster's capacity
Examples
Input: ([10, 20], 3, [(0, 0, 5), (0, 1, 13), (1, 1, 8), (2, 0, 2), (2, 1, 2)])
Expected Output: 37
Explanation: Daily remaining GPUs are [5, 7], [10, 12], and [8, 18]. Take the daily maximums: 7 + 12 + 18 = 37.
Input: ([4, 6], 2, [])
Expected Output: 12
Explanation: Each day the best cluster has 6 GPUs, so the total is 6 + 6.
Input: ([5], 3, [(0, 0, 2), (1, 0, 5)])
Expected Output: 8
Explanation: Only one cluster exists. Remaining GPUs are 3, 0, and 5.
Input: ([], 3, [])
Expected Output: 0
Explanation: There are no clusters to choose from.
Hints
- First compute the remaining GPUs for every day and cluster.
- With unlimited switching, the best choice for each day is independent of all other days.
Part 3: Maximum Usable GPUs with At Most K Switches
Constraints
- 0 <= num_days <= 500
- 0 <= len(capacities) <= 100
- 0 <= len(usages) <= 200000
- 0 <= k
- 0 <= gpu_used
- For every day and cluster, total gpu_used does not exceed that cluster's capacity
Examples
Input: ([10, 20], 4, [(0, 1, 15), (1, 0, 8), (2, 1, 15), (3, 0, 8)], 1)
Expected Output: 55
Explanation: Daily remaining GPUs are [10, 5], [2, 20], [10, 5], [2, 20]. With one switch, the best plan is cluster 0 on day 0, then cluster 1 on days 1 to 3: 10 + 20 + 5 + 20 = 55.
Input: ([10, 20], 4, [(0, 1, 15), (1, 0, 8), (2, 1, 15), (3, 0, 8)], 3)
Expected Output: 60
Explanation: With three switches, you can alternate clusters every day and take 10 + 20 + 10 + 20 = 60.
Input: ([10, 20], 4, [(0, 1, 15), (1, 0, 8), (2, 1, 15), (3, 0, 8)], 0)
Expected Output: 50
Explanation: With no switches, pick one cluster for all days. Cluster 1 gives 5 + 20 + 5 + 20 = 50, which is better than staying on cluster 0.
Input: ([7], 3, [(0, 0, 2), (2, 0, 7)], 5)
Expected Output: 12
Explanation: Only one cluster exists, so switching does not matter. Remaining GPUs are 5, 7, and 0.
Input: ([3, 4], 0, [], 2)
Expected Output: 0
Explanation: There are no days to schedule.
Hints
- First convert the raw usage list into a day-by-day remaining GPU table.
- Use dynamic programming with state based on day, current cluster, and how many switches have been used so far. To optimize transitions, keep the best and second-best previous values for each switch count.