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.
1 ≤ n ≤ 2³¹ − 11 and n.Maintain the invariant: every version ≤ lo is known good, every version ≥ hi is known bad.
4