New version: https://leetcode.com/discuss/interview-question/394347/
You are a gardener and you take care of your plants. The plants are planted in a row and each of them needs a specific amount of water. You are about to water them using a watering can. To avoid mistakes like applying too much water, or not watering a plant at all, you have decided to:
You start at the water container, which is positioned one step before the first plant. How many steps will you take, in order to water all the plants in the row? You must take one step to move to the next or the previous plant (all plants are positioned one step apart from each other).
Given an array plants of n integers (for the amount of water needed by each plan) and the watering can capacity, return the number of steps needed to water all the plants.
Example:
Input: plants = [2, 4, 5, 1, 2], capacity = 6
Output: 17
Explanation:
First you water plants[0] and plants[1] (2 steps).
Then you have to go back to refill (2 steps) and water plants[2] and plants[3] (4 steps).
Then again you have to refill (4 steps) and water plants[4] (5 steps).
So 2 + 2 + 4 + 4 + 5 = 17.Constraints:
n is an integer within the range [1..1,000];plants is an integer within the range [1..1,000,000];capacity is an integer within the range [1..1,000,000,000];