1326. Minimum Number of Taps to Open to Water a Garden
Last updated
Last updated
https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden
There is a one-dimensional garden on the x-axis. The garden starts at the point 0
and ends at the point n
. (i.e The length of the garden is n
).
There are n + 1
taps located at points [0, 1, ..., n]
in the garden.
Given an integer n
and an integer array ranges
of length n + 1
where ranges[i]
(0-indexed) means the i-th
tap can water the area [i - ranges[i], i + ranges[i]]
if it was open.
Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
1 <= n <= 104
ranges.length == n + 1
0 <= ranges[i] <= 100