Find GPU Capacity and Drain a Node
Learn this problemProblem statement
You manage a cluster of GPU nodes. Node i has name nodeNames[i] and total capacity nodeGpus[i]. Pod j has name podNames[j], requires podGpuRequirements[j] GPUs, and currently runs on node index podNodeIndices[j].
First, consider a new pod that requires newPodRequiredGpus GPUs. Compute every node whose current free capacity can fit that request.
Then delete the node named deleteNodeName. Its running pods become displaced and must be assigned to the remaining nodes without moving any pod that already runs on a remaining node.
For this exercise, assume rescheduling must succeed whenever any capacity-feasible assignment exists. A greedy dead end is not proof of impossibility. Explore displaced pods by descending GPU requirement, breaking ties by their original order. For each pod, try remaining nodes in their original input order. Choose the first complete assignment found by this exact search, and report assignments in the displaced pods' original order.
Required result
Return exactly two rows:
- The eligibility row contains
nodeName:freeGpusfor every node that can fit the new request before deletion, in node input order. - The rescheduling row contains
podName:nodeNamefor every displaced pod, in original pod order. If no complete assignment exists, this row is exactly["IMPOSSIBLE"].
Function
analyzeGpuCluster(nodeNames: String[], nodeGpus: int[], podNodeIndices: int[], podNames: String[], podGpuRequirements: int[], newPodRequiredGpus: int, deleteNodeName: String) → List<List<String>>Examples
Example 1
nodeNames = ["node-1","node-2","node-3","node-4","node-5"]nodeGpus = [8,8,8,8,8]podNodeIndices = [0,0,1,1,2,3,3]podNames = ["pod-a","pod-b","pod-c","pod-d","pod-e","pod-f","pod-g"]podGpuRequirements = [2,4,4,4,4,2,2]newPodRequiredGpus = 2deleteNodeName = "node-2"return = [["node-1:2","node-3:4","node-4:4","node-5:8"],["pod-c:node-3","pod-d:node-4"]]Before deletion, the free capacities are 2, 0, 4, 4, 8, so every node except node-2 can fit the 2-GPU request. Deleting node-2 displaces two 4-GPU pods. In search order, pod-c fits first on node-3 and pod-d fits first on node-4.
Example 2
nodeNames = ["node-a","node-b","node-gone"]nodeGpus = [8,6,14]podNodeIndices = [2,2,2]podNames = ["pod-big","pod-left","pod-right"]podGpuRequirements = [6,4,4]newPodRequiredGpus = 7deleteNodeName = "node-gone"return = [["node-a:8"],["pod-big:node-b","pod-left:node-a","pod-right:node-a"]]Putting the 6-GPU pod on node-a first would strand one 4-GPU pod. Exact search backtracks and puts it on node-b, leaving all 8 GPUs on node-a for the two 4-GPU pods.
Example 3
nodeNames = ["left","right","gone"]nodeGpus = [3,3,4]podNodeIndices = [2]podNames = ["wide"]podGpuRequirements = [4]newPodRequiredGpus = 3deleteNodeName = "gone"return = [["left:3","right:3"],["IMPOSSIBLE"]]Both remaining nodes can fit the independent 3-GPU request, but neither can fit the displaced 4-GPU pod, so complete rescheduling is impossible.
Constraints
1 <= nodeNames.length <= 12and all node names are unique.nodeGpus.length == nodeNames.lengthand every capacity is between1and64.podNodeIndices.length == podNames.length == podGpuRequirements.length <= 60, and pod names are unique.- Every pod index is valid, every pod requires between
1and64GPUs, and current usage never exceeds a node's capacity. deleteNodeNamenames exactly one node, and at most10pods run on it.1 <= newPodRequiredGpus <= 64.