Practice Watering Plants
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
plants[i] is the water required by plant i. Plants stand at positions 0 through plants.length - 1 and the river is at -1. Begin at the river with a full can of capacity and water plants from left to right. Before moving to the next plant, return to the river to refill only if the remaining water cannot fully water that plant; early refills are forbidden. Return the total unit-distance steps until every plant is watered.
Source: Watering Plants on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
plants = [2,2,3,3], capacity = 5
14
# Example 2
plants = [1,1,1,4,2,3], capacity = 4
30
# Example 3
plants = [7,7,7,7,7,7,7], capacity = 8
49
Constraints
Related LeetCode Problems
Practice more problems similar to Watering Plants.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.