You are a product manager leading a team developing a new product. Versions [1..n] are all derived from version 1, and once a version is bad, every version after it is also bad. You are given an API isBadVersion(v) that returns whether version v is bad. Return the first bad version using as few API calls as possible.
The answer space is monotone — false, false, ..., false, true, ..., true — so this is a textbook binary search on the answer space with O(log n) calls.
Example: n = 5, the first bad version is 4 → 4.
4