range[i] is how many towers ahead tower i can relay to. Starting at tower 0, return the minimum hops to reach the last tower. It's guaranteed reachable.
Signature
minHops(reach: int[]) → intExample 1
reach = [2,3,1,1,4]
output = 2
0 → 1 → 4: 2 hops
Example 2
reach = [2,3,0,1,4]
output = 2
Constraints
1 ≤ n ≤ 10^40 ≤ range[i] ≤ 1000last tower reachable
⌘/Ctrl + Enter runs examples
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).