First Bad Version
easyGiven a version control system where all versions after a bad version are bad, find the first bad version
First Bad Version
Key Insight
Binary search the version space and keep the earliest index where isBadVersion(mid) is true.
Step 1Initialize
False ... false ... true ... true
L
R
1
02
13
24
35
46
57
6Search space: [0..6]
Versions 1..n, with all good versions before the first bad version.
1 / 4