Minimum taps water garden

Write codeHard35 min

Your task

A garden runs along a line from point 0 to point n. There are n+1 taps at integer points 0..n; tap i has range ranges[i], meaning when open it waters the closed interval [i - ranges[i], i + ranges[i]]. Return the minimum number of taps to open so the entire garden [0, n] is watered, or -1 if it is impossible. Constraints: 1 <= n <= 10^4, 0 <= ranges[i] <= 100, len(ranges) == n + 1.

Examples

min_taps(n: int, ranges: list[int]) -> int
Example 1
Inputmin_taps(5, [3, 4, 1, 1, 0, 0])
Output1