Top Coding Interview Question – Solved

6 Live
Watering plants Imagine you are a park ranger responsible for maintaining N plants along a hiking trail. The plants are arranged in a straight line and numbered from 0 to N - 1: with the ith plant located at x = i. You have a water source at x = -1, which you must use to refill your watering can. Each plant requires a different amount of water and you must water them in order, from left to right. If you run out of water while watering a plant, you must return to the water source to refill your watering can before continuing to the next plant. You cannot refill your watering can before it is empty or it cannot water the next plant, and it takes one step to move one unit on the x-axis. Determine the number of steps you must take to water all of the plants along the hiking trail successfully. Notes - You start at -1. - The location of the plants starts from O. Function description Complete the function solution() provided in the editor. The function takes the following 3 parameters and returns the solution: - N. Represents the number of plants - C : Represents the capacity of the water can - plants : Represents the water requirements of the plant Input format for custom testing Note: Use this Input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code -The first line contains N denoting the number of plants. -The second line contains C denoting the capacity of the can

Asked in: No companies listed

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |