Problem
Your product has versions 1 to n. One release introduced a bug, and every version after a bad one is also bad. You are given a function is_bad(version) (TypeScript: isBad(version)) that returns true for bad versions. Return the first bad version.
Each call to is_bad is expensive (imagine a full test run), and the tests count them, so call it as few times as you can.
Example 1
- Input
- n = 5, first bad = 4
- Output
- 4
- Why
- 3 is good, 4 and 5 are bad
Example 2
- Input
- n = 1, first bad = 1
- Output
- 1
Constraints
1 <= bad <= n <= 2^31 - 1At least one version is bad.