Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwoCrystalBalls Solution Edge Case #22

Open
a89529294 opened this issue Oct 1, 2022 · 2 comments
Open

TwoCrystalBalls Solution Edge Case #22

a89529294 opened this issue Oct 1, 2022 · 2 comments

Comments

@a89529294
Copy link

a89529294 commented Oct 1, 2022

If true happens right at one of the jump points the current solution will return -1

test("two crystal balls", function () {
    const data = [
        false,
        false,
        false,
        true,
        true,
        true,
        true,
        true,
        true,
        true,
    ];
    const idx = 3;
    expect(two_crystal_balls(data)).toEqual(idx);
    expect(two_crystal_balls(new Array(821).fill(false))).toEqual(-1);
});

We just need to modify the second loop in TwoCrystalBalls.ts like this

for (let j = 0; j < jmpAmount + 1 && i < breaks.length; i++, j++) {
        if (breaks[i]) return i;
    }
@echosonusharma
Copy link

or you could just j <= jupAmount. i guess you are right!

@MikesGlitch
Copy link

I've been pulling my hair out on this one 😆 Yeah I ended up with the same j <= jumpIncrement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants