Shubham Sourabhthe room · director's cutplain résumé
Room 04 · The Grind — Greedy

Jump Game VII

MEDIUM✓ CHIP-TIMEDLC #1871 — FULL STATEMENT

The briefingthe full drill, in my own words

The drill: On a strip of '0's and '1's, start at the front — always a '0' — and hop only onto other '0' cells. Each hop's length must fall inside a fixed [min, max] range. Decide whether the far end is reachable.

This site verifies the drill as a hop across a strip of '0' and '1' cells: the starting cell at index zero is always a '0', and every hop must land on a '0' cell too — landing on a '1' is never allowed.

Every hop's length has to fall within a fixed [minJump, maxJump] window measured in index positions — nothing shorter, nothing longer, regardless of how far a '0' cell might otherwise sit.

The question is whether some chain of such hops, starting at the front, can ever land exactly on the strip's final index.

  • the strip's first and last characters are always '0'
  • every hop lands only on '0' cells; '1' cells are never valid landings
  • hop length must fall between minJump and maxJump inclusive, every time
  • hops always move forward toward the end of the strip
EX 01
s = "0000000" · minJump = 2 · maxJump = 3
→ true
all open cells, window jumps chain to the end
EX 02
s = "0110" · minJump = 1 · maxJump = 1
→ false
adjacent-only hops blocked by a run of ones
EX 03
s = "00000" · minJump = 1 · maxJump = 2
→ true
flexible window reaches the last cell

The hintstake only what you need

HINT 1 THE NUDGE

From each landing spot, trying every jump length in [minJump, maxJump] one at a time re-derives the same reachability fact over and over for overlapping windows. What does 'is position i reachable' actually depend on?

HINT 2 THE STRUCTURE

Position i is reachable exactly when s[i] is '0' AND some already-reachable position falls in the window [i − maxJump, i − minJump]. That's a range question, not an all-pairs question.

HINT 3 ONE STEP FROM THE ANSWER

Keep a running prefix count of reachable positions. Position i is reachable when s[i] == '0' and the reachable-count inside [i − maxJump, i − minJump] is nonzero — one subtraction of two prefix sums, O(1) per position.

Coach's boardthe pattern, step by step

THE WINDOWED HOPPATTERN · SLIDING WINDOW OF REACHABILITYs = "011010" · minJump = 2 · maxJump = 3
0
1
1
0
1
0
REACHABLE INDICES
0 → reachable
STEP 1

Strip "011010", hops must land on '0' and span between minJump=2 and maxJump=3. Index 0 is reachable — that's the start.

STEP 1 / 7 · ← → WORK TOO

The splitstwo paces, two languages

grind/jump-game-vii.py — RACE PACE
LANG ▸
PACE ▸
class Solution:
    def canReach(self, s: str, minJump: int, maxJump: int) -> bool:
        n = len(s)
        dp = [False] * n
        dp[0] = True
        prefix = [0] * (n + 1)
        prefix[1] = 1  # dp[0] is reachable
        for i in range(1, n):
            lo = max(0, i - maxJump)
            hi = i - minJump
            if s[i] == "0" and hi >= lo and prefix[hi + 1] - prefix[lo] > 0:
                dp[i] = True
            prefix[i + 1] = prefix[i] + (1 if dp[i] else 0)
        return dp[n - 1]
TIME O(N)SPACE O(N)PYTHON · RACE PACE · 14 LN

✓ CHIP-TIMEDALL 4 SOLUTIONS RAN GREEN AGAINST SELF-AUTHORED CASES IN CI · JDK 21 · CPYTHON 3.12 · NOTHING PUBLISHES RED