We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I wrote a manual test to investigate this algo better since I found it very interesting.
This test fails and returns -1
-1
test("custom test", () => { const data = [ false, false, false, false, false, false, false, false, false, true, true, true, ]; expect(two_crystal_balls(data)).toEqual(9); });
The way I've found to make it pass was considering the extra/last step like:
// Note the `j <= jumpAmount` instead of ` j < jumpAmount` for (let j = 0; j <= jumpAmount && i < breaks.length; ++j, ++i) { if (breaks[i]) { return i; } }
Keeping that <= condition still passes the other default tests from Prime. Removing it will break my test case. Am I right or am I missing something?
<=
The text was updated successfully, but these errors were encountered:
Of course, this is the algo (exactly what it is in Primeagen video)
export default function two_crystal_balls(breaks: boolean[]): number { const jumpAmount = Math.floor(Math.sqrt(breaks.length)); let i = jumpAmount; for (; i < breaks.length; i += jumpAmount) { if (breaks[i]) { break; } } i -= jumpAmount; for (let j = 0; j <= jumpAmount && i < breaks.length; ++j, ++i) { if (breaks[i]) { return i; } } return -1; }
Sorry, something went wrong.
The condition should be j <= jmpAmount as seen on the screenshot.
j <= jmpAmount
No branches or pull requests
I wrote a manual test to investigate this algo better since I found it very interesting.
This test fails and returns
-1
The way I've found to make it pass was considering the extra/last step like:
Keeping that
<=
condition still passes the other default tests from Prime. Removing it will break my test case. Am I right or am I missing something?The text was updated successfully, but these errors were encountered: