Compute Remaining GPUs With Switching Limits
Mistral AISoftware Engineer · Technical ScreenLast updated
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.
Suppose you manage n GPU clusters with fixed daily capacities capacity[i]. Each day starts fresh with the full capacity, because all GPUs are returned overnight. You are given a list of usage records with the fields:
day: integer day numbercluster: 0-based cluster indexgpu: number of GPUs consumed by that usage on that day
Assume all records are valid and the total usage for any cluster on any day never exceeds its capacity.
Answer the following related questions:
- For every distinct day that appears in the input, in increasing day order, compute the remaining GPUs in each cluster at the end of that day. Return a 2D array where each row contains the remaining capacity of every cluster for one day.
- A new workload can run on exactly one cluster per day and may switch to any cluster between days with no limit. What is the maximum total number of GPUs it can access across all days?
- Now suppose that workload may switch clusters at most
Ktimes over the whole time horizon. A switch occurs when the chosen cluster on one day differs from the chosen cluster on the next day. Compute the maximum total GPUs it can access.
Example:
capacity = [10, 20]- daily remaining capacities might be
[[5, 7], [10, 12], [8, 18]]
For part 2, the best total is 7 + 12 + 18 = 37.
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.