First Broken Build
A project's builds are numbered from 0, and their results are written in the string builds: P for a build that passed, F for one that failed. At some build a bug got in, and every build from that one on fails; every build before it passed.
Return the index of the first failed build, or -1 if every build passed.
Imagine each check is slow to run: look at as few builds as you can.
Examples
builds = "PPPFFF" → 3
builds = "PPPP" → -1
builds = "FFF" → 0
builds = "PF" → 1Constraints
- Between 0 and 100,000 builds. Every
Pcomes before everyF. - Aim for O(log n): a history four times longer should take only a couple of checks more. Python's
str.indexandin, and TypeScript'sindexOf, read from the start.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 8 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.