A visual regression test started failing somewhere in your branch. You ran it on every commit, oldest first, and stored the results in results: false means the test passed and true means it failed.
Once a commit breaks the test, every later commit fails too, so results is some false values followed by some true values.
Write firstFailing(results) that returns the index of the first true, or -1 if every commit passed. Look at as few results as you can.
Input: results = [false,false,false,true,true] Output: 3
Commit 3 is the first one where the test fails.
Input: results = [false,false] Output: -1
Every commit passed.
1 <= results.length <= 100000false comes after a true.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #151 First Failing Commit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.