Code RoomBattery capacity planning
MediumPrep Room Coding #4863

Battery capacity planning

CodingAlgorithms & data structuresMid–Senior~28 min

A remote relay site runs on solar power with a battery pack and a diesel backup. During hour i the panels deliver harvest[i] units of energy and the equipment draws load[i] units. The pack starts the day full. At the end of each hour its charge moves by harvest[i] minus load[i]. Charge above the pack capacity is lost, and any shortfall below zero is covered by the generator, which burns one unit of fuel per unit supplied and leaves the pack empty. Return the smallest whole capacity that keeps the generator's fuel for the whole day at or below budget. The two lists have the same length, every value is non-negative, and budget is non-negative.

Implement
smallest_pack_capacity(harvest: list[int], load: list[int], budget: int) → int
Examples
in[[10,0],[0,6],0]out6
in[[0,0],[3,4],2]out5
in[[9,9,9],[1,2,3],0]out0
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
[[10,0],[0,6],0]6not run yetsample
[[0,0],[3,4],2]5not run yetsample
[[9,9,9],[1,2,3],0]0not run yetsample