Watering plants best and easy to understand approach with O(N) TC
class Solution {
    public int wateringPlants(int[] arr, int capacity) {
        int n = capacity;
        int count=0;
        for(int i = 0;i<arr.length;i++){
            if(n<arr[i]){
                n = capacity;
                count+= 2*i+1;
                n= n-arr[i];
            }else{
            count++;
            n = n-arr[i];
}

   }

        return count;
    }
}
Comments (0)