← All Exercises
Place Pods Within Node Capacity
intermediatejavascript
Background
Unschedulable pods are usually a capacity accounting problem, not a scheduler bug. Computing the placement deterministically separates "full" from "misconfigured requests".
Problem
Greedily place pods onto nodes with enough allocatable CPU and memory, and report which pods cannot be scheduled plus per-node usage.
Input
JSON object: { nodes: [{ name, allocatableCpu, allocatableMem }], pods: [{ name, cpu, mem }] }Output
JSON object: { unschedulable: string[], used: [{ name, cpuUsed, memUsed }] }Sample tests
Sample 1
Input: {"nodes":[{"name":"n1","allocatableCpu":2,"allocatableMem":4096}],"pods":[{"name":"api","cpu":1,"mem":1024},{"name":"worker","cpu":1.5,"mem":2048}]}Expected: {"unschedulable":["worker"],"used":[{"name":"n1","cpuUsed":1,"memUsed":1024}]}Sample 2
Input: {"nodes":[{"name":"n1","allocatableCpu":2,"allocatableMem":4096},{"name":"n2","allocatableCpu":2,"allocatableMem":4096}],"pods":[{"name":"api","cpu":1,"mem":1024},{"name":"worker","cpu":1.5,"mem":2048}]}Expected: {"unschedulable":[],"used":[{"name":"n1","cpuUsed":1,"memUsed":1024},{"name":"n2","cpuUsed":1.5,"memUsed":2048}]}Your solution
Learning objective
Diagnose pod placement from capacity arithmetic rather than scheduler events alone.