SR-Sunny-Raj / Hacktoberfest2021-DSA

NOTE -: For Hacktoberfest2022 please refer this repository https://github.com/SR-Sunny-Raj/Hacktoberfest2022-for-everyone to make your contribution. If You know the implementation of any DSA related topic/problem then you can contribute it in this repo. Raise Genuine PRs only. Your PRs will be accepted, keep patience. Star this Repo. You aren't allowed to Update README.md. Welcoming developers, content writers, and programming enthusiasts.
https://sr-sunny-raj.github.io/Hacktoberfest2021-DSA/
MIT License
230 stars 989 forks source link

Watering plants in C++ (Leetcode) #1509

Closed VishnuBhaarath closed 2 years ago

VishnuBhaarath commented 2 years ago

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.

Platform: Leetcode

Can you assign this issue to me.

VishnuBhaarath commented 2 years ago

Have added the solution #1510