Plant watering steps

Write codeMedium14 min

Your task

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.

Examples

watering_steps(plants: list[int], capacity: int) -> int
Example 1
Inputwatering_steps([2, 2, 3, 3], 5)
Output14