Code RoomPlant watering steps
MediumPrep Room Coding #652

Plant watering steps

CodingAlgorithms & data structuresEntry–Mid~14 min

You water a row of office plants left to right using a can that holds capacity units. plants[i] is how much water plant i needs (each need is at most capacity). The tap sits one step left of plant 0; you start there with a full can. Walking between adjacent positions costs one step, watering itself is free, and you only ever water the next unwatered plant. If the can holds too little for that plant you must first walk back to the tap, refill, and walk out again. Return the total steps taken to water every plant.

Implement
watering_steps(plants: list[int], capacity: int) → int
Examples
in[[2,2,3,3],5]out14
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 14 min
InputExpectedGot
[[2,2,3,3],5]14not run yetsample