Skip to content

Weak Test Cases for Jump Game VII #5580

@shahadad-shishir

Description

@shahadad-shishir

Bug Report for https://neetcode.io/problems/jump-game-vii

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

Issue
The current test suite allows an incorrect Greedy approach to pass. This logic fails on LeetCode but passes here due to a lack of "Anti-Greedy" test cases that enforce landing strictly on '0's.

The "False Positive" Logic
The following code incorrectly passes the current suite:

bool canReach(string s, int minJump, int maxJump) {
    if(s.back() == '1') return false;
    int l = 0, r = 0;
    while(r < s.size() - 1) {
        int farthest = 0;
        for(int i = l; i <= r; i++) {
            if(s[i] == '0') farthest = max(farthest, i + maxJump);
        }
        if(farthest == 0) return false;
        l = r + 1; 
        r = farthest;
    }
    return r >= s.size() - 1;
}

Failing Test Case
Cross-referencing with LeetCode, this case reveals the discrepancy:

Input: s = "011111000111000001011111010", minJump = 6, maxJump = 8
Expected: false
Actual: true (Greedy incorrectly "jumps" over invalid regions)

Suggested Action
Add the above test case to the suite to ensure only valid O(N) BFS or DP solutions pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions