forked from techyminati/python_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatering-plants.py
More file actions
24 lines (23 loc) · 1.44 KB
/
watering-plants.py
File metadata and controls
24 lines (23 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Answer to this - https://leetcode.com/problems/watering-plants/
#You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.
#Each plant needs a specific amount of water. You will water the plants in the following way:
#Water the plants in order from left to right.
#After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.
#You cannot refill the watering can early.
#You are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.
#Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.
plants = input("Enter the capacity of water required to water each plant seperated by spaces\n")
list = plants.split()
original_capacity = capacity = int(input("Enter the capacity of water that can be stored in the bucket\n"))
i = 0
index = 0
steps = 0
while i < len(list) :
if int(list[i]) > capacity :
steps = steps + 2 * i + 1
capacity = original_capacity
else :
steps += 1
capacity = capacity - int(list[i])
i += 1
print(steps)