Minimum Number of Taps to Open to Water a Garden
You have a garden of length n consisting of n + 1 spots labeled from 0 to n. You have n hoses connected to a water source, each hose has an input nozzle that can be put at any spot to water the plants. There is a tap with an output nozzle also connected to the water source at the position 0.
Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) is the distance you can water the plant at spot i, return the minimum number of hoses you need to water the entire garden. If you cannot water the entire garden, return -1.
Ada AI
I want to discuss a solution
Help me solve this
Give more examples
What's wrong with my code?
How to use 'for loop' in javascript?
javascript (node 13.12.0)