Loading repovive.com/problems/faang/1
This problem is based on a Google interview problem described here.
You have plants in a row, numbered from to . Plant needs units of water. You start at the river (position ) with a watering can that holds at most 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 ) counts as one step.
Return the total number of steps taken to water all plants.