Practice Minimum Number of Taps to Open to Water a Garden
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Number of Taps to Open to Water a Garden
Problem Statement
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.
Source: Minimum Number of Taps to Open to Water a Garden on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 5, ranges = [3,4,1,1,0,0]
1
# Example 2
n = 3, ranges = [0,0,0,0]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Number of Taps to Open to Water a Garden.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.