Loading...
You are given an integer n and an array ranges of length n + 1. The segment [0, n] on the number line must be covered. There are n + 1 points at positions 0, 1, ..., n. Activating point i covers the interval [i - ranges[i], i + ranges[i]].
Return the minimum number of points to activate so that the whole segment [0, n] is covered, or -1 if that is impossible.
Input: n = 5, ranges = [3, 4, 1, 1, 0, 0]
Output: 1
Explanation: Point 1 covers [1-4, 1+4] = [-3, 5], which contains [0, 5].
Input: n = 3, ranges = [0, 0, 0, 0]
Output: -1
Explanation: No point covers anything beyond itself.
ranges.length =n+1ranges[i] ≤100Click "Run" to test with sample cases or "Submit" to run all tests.