Code Room
CodingMediumcod-g1452
Subject GreedyLevel Entry–Mid~14 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.