Loading repovive.com/problems/faang/1
This problem is based on a Google interview problem described here.
You have n plants in a row, numbered from 0 to n−1. Plant i needs pi units of water. You start at the river (position −1) with a watering can that holds at most K units of water, initially full.
You walk forward one plant at a time. You have two choices:
Each step between adjacent positions (including between the river and plant 0) counts as one step.
Return the total number of steps taken to water all plants.
ans
4 5 2 2 3 3
14
3 3 1 1 1
3
1 5 5
1