You are given a 0-indexed binary string s and two integers minJump and maxJump.

In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:

  • i + minJump <= j <= min(i + maxJump, s.length - 1), and
  • s[j] == '0'

Return true if you can reach index s.length - 1 in s, or false otherwise.

Input & Output

Example 1 — Basic Jump Sequence
$ Input: s = "011010", minJump = 2, maxJump = 3
Output: true
💡 Note: Start at index 0, jump to index 3 (jump of size 3), then jump to index 5 (jump of size 2). Both positions contain '0' and are within jump constraints.
Example 2 — Blocked Path
$ Input: s = "01101110", minJump = 2, maxJump = 3
Output: false
💡 Note: From index 0, we can reach index 2 or 3. From index 3, we can reach indices 5 or 6, but both contain '1'. No valid path to the last index.
Example 3 — Minimum Jump Only
$ Input: s = "0101", minJump = 1, maxJump = 1
Output: false
💡 Note: From index 0, jump to index 1 ('1' - invalid). Cannot proceed further, so cannot reach index 3.

Constraints

  • 2 ≤ s.length ≤ 105
  • s[i] is either '0' or '1'
  • s[0] == '0'
  • 1 ≤ minJump ≤ maxJump < s.length

Visualization

Tap to expand
Jump Game VII: Can we reach the end?s = "011010", minJump = 2, maxJump = 3011010012345Jump 3Jump 2Rules:• Can only land on '0' positions• Jump distance: 2 ≤ jump ≤ 3• Goal: Reach the last position✓ Path found: 0 → 3 → 5
Understanding the Visualization
1
Input
Binary string with jump constraints
2
Process
Find valid jumps avoiding '1' positions
3
Output
True if last position is reachable
Key Takeaway
🎯 Key Insight: Use sliding window with DP to efficiently track which positions can jump to current position
Asked in
Meta 25 Google 20 Amazon 18 Microsoft 15
32.0K Views
Medium Frequency
~25 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen