Search
⌘K

Leetcode 2079. Watering Plants

Simulate greedily watering plants left-to-right with a fixed-capacity can starting at the river: whenever remaining water can't fully cover the next plant you must walk back to the river and return, so accumulate per-plant walking plus the extra round-trip distance to refill. The challenge is computing the total steps efficiently by tracking remaining water and adding 2*(i+1) distance whenever a refill is needed (O(n) time, O(1) space).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.