Practice Watering Plants II
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 needed by plant i. Alice and Bob begin with full cans of capacityA and capacityB and water simultaneously from the left and right ends, respectively. Each plant takes one equal-time step. Before a plant, refill only if the current water is insufficient. If both reach the same plant, whoever currently has more water waters it, with Alice winning ties. Return the total refill count.
Source: Watering Plants II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
plants = [2,2,3,3], capacityA = 5, capacityB = 5
1
# Example 2
plants = [2,2,3,3], capacityA = 3, capacityB = 4
2
# Example 3
plants = [5], capacityA = 10, capacityB = 8
0
Constraints
Related LeetCode Problems
Practice more problems similar to Watering Plants II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.