> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Jump Game VII Python Solution with Tests

> Tested Python solution for LeetCode 1871 with 15 pytest cases. Generate a practice environment with lcpy.

LeetCode 1871, Medium. Topics: String, Dynamic Programming, Sliding Window, Prefix Sum. [View on LeetCode](https://leetcode.com/problems/jump-game-vii/description/).

Generate this problem as a practice environment: tested reference solution, 15 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1871   # by problem number
lcpy gen -s jump_game_vii   # by problem name
```

## Problem

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.

### Examples

```
Input: s = "011010", minJump = 2, maxJump = 3
Output: true
Explanation:
In the first step, move from index 0 to index 3.
In the second step, move from index 3 to index 5.
```

```
Input: s = "01101110", minJump = 2, maxJump = 3
Output: false
```

### Constraints

* 2 \<= s.length \<= 10^5
* s\[i] is either '0' or '1'.
* s\[0] == '0'
* 1 \<= minJump \<= maxJump \< s.length

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/jump_game_vii/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/jump_game_vii/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(n)
    def can_reach(self, s: str, min_jump: int, max_jump: int) -> bool:
        n = len(s)
        if s[n - 1] != "0":
            return False

        reachable = [False] * n
        reachable[0] = True
        window_count = 0

        for i in range(1, n):
            if i >= min_jump and reachable[i - min_jump]:
                window_count += 1
            if i > max_jump and reachable[i - max_jump - 1]:
                window_count -= 1

            if s[i] == "0" and window_count > 0:
                reachable[i] = True

        return reachable[n - 1]
```

## Complexity

| Time | Space |
| ---- | ----- |
| O(n) | O(n)  |

## Tags

[NeetCode 250](/catalog/neetcode-250), [NeetCode All](/catalog/neetcode).
