FastPrepGPU Capacity With Limited Cluster Switching

GPU Capacity With Limited Cluster Switching

Mistral AI logoMistral AI● HardFULLTIMEOA
Learn

Problem statement

You operate several GPU clusters for a sequence of days. Cluster c has a fixed capacity capacities[c]. Each row [day, cluster, used] records the GPUs already occupied on that day; an omitted pair has zero usage.

Choose exactly one cluster per day. Its contribution is capacity - used. Moving from one cluster to a different cluster between consecutive days consumes one switch. Return the maximum total remaining GPU capacity obtainable with at most maxSwitches switches.

Every day and cluster pair appears at most once in usages.

Function

maximizeRemainingGpu(capacities: int[], numDays: int, usages: int[][], maxSwitches: int) → int

Examples

Example 1

capacities = [10,8]numDays = 3usages = [[0,0,9],[0,1,1],[1,0,0],[1,1,7],[2,0,9],[2,1,0]]maxSwitches = 1return = 19

Use cluster 1 on day 0, switch to cluster 0 on day 1, and remain there on day 2 for 7 + 10 + 1 = 18.

Example 2

capacities = [5,9]numDays = 2usages = []maxSwitches = 0return = 18

With no switches, staying on cluster 1 contributes 9 on each day.

Constraints

  • 1 <= capacities.length <= 50
  • 1 <= numDays <= 200
  • 0 <= maxSwitches < numDays
  • 0 <= used <= capacities[cluster] <= 10000
See Mistral AI hiring insights
public int maximizeRemainingGpu(int[] capacities, int numDays, int[][] usages, int maxSwitches) {
  // Write your code here.
}
capacities[10,8]
numDays3
usages[[0,0,9],[0,1,1],[1,0,0],[1,1,7],[2,0,9],[2,1,0]]
maxSwitches1
expected19
Checking account…