Can a Vehicle Reach the Last Toll Booth With Bounded Hops
Along a highway, toll booths are either open ('0') or closed ('1'). From an open booth a FASTag vehicle may advance by any distance between a minimum and maximum jump, but can only land on an open booth. Decide whether it can reach the final booth from the first.
Problem
Given a 0-indexed binary string s where '0' is an open booth and '1' is closed, starting at index 0 (guaranteed open), you may move from index i to index j if minJump <= j - i <= maxJump and s[j] == '0'. Return true if you can reach index s.length - 1.
Input
A binary string s and integers minJump and maxJump.
Output
A boolean: whether the last booth is reachable.
Constraints
- 2 <= s.length <= 10^5
- 1 <= minJump <= maxJump < s.length
- s[0] == '0'.
Examples
Example 1
Input
s = "011010", minJump = 2, maxJump = 3
Output
true
0 -> 3 -> 5 reaches the last open booth.
Example 2
Input
s = "01101110", minJump = 2, maxJump = 3
Output
false
No valid hop sequence reaches the end.