Code RoomMinimum provisioning step
MediumPrep Room Coding #4920

Minimum provisioning step

CodingAlgorithms & data structuresMid–Senior~28 min

A platform team writes a capacity plan, one row per week. In week i the fleet has to run at least min_nodes[i] machines to hold the error budget and at most max_nodes[i] machines to hold the cost budget, and every row is valid, so a floor never exceeds its own ceiling. Provisioning limits how far the count may move between neighbouring weeks: a plan is buildable at step s when any two consecutive counts differ by at most s. Return the smallest step that admits at least one plan honouring every week's floor and ceiling. Return 0 for a plan shorter than two weeks. Comparing neighbouring rows alone is not enough, because a roomy row in the middle still has to be crossed in one direction.

Implement
smallest_fleet_step(min_nodes: list[int], max_nodes: list[int]) → int
Examples
in[[4,4,12],[4,30,12]]out4
in[[6,2,9],[10,20,14]]out0
in[[0,0,10],[0,100,10]]out5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 28 min
InputExpectedGot
[[4,4,12],[4,30,12]]4not run yetsample
[[6,2,9],[10,20,14]]0not run yetsample
[[0,0,10],[0,100,10]]5not run yetsample