Problem
A garden lies on a line from 0 to n. There are n + 1 taps at positions 0, 1, ..., n. Tap i, when open, waters [i - ranges[i], i + ranges[i]]. Return the minimum number of taps to open so that the whole garden [0, n] is watered, or -1 if that is impossible.
Example 1
- Input
- n = 5, ranges = [3, 4, 1, 1, 0, 0]
- Output
- 1
- Why
- tap 1 waters [-3, 5]
Example 2
- Input
- n = 3, ranges = [0, 0, 0, 0]
- Output
- -1
Example 3
- Input
- n = 7, ranges = [1, 2, 1, 0, 2, 1, 0, 1]
- Output
- 3
Constraints
1 <= n <= 10^4ranges.length == n + 10 <= ranges[i] <= 100