You're a product manager leading a software development team, and your latest product release has failed quality assurance! ๐ฑ
Here's the challenge: your team develops software versions sequentially [1, 2, 3, ..., n], where each version builds upon the previous one. Unfortunately, once a bad version is introduced, all subsequent versions inherit the same issues and become bad too.
Your mission: Find the first bad version that started this cascade of problems!
๐ง Available Tool: You have access to an API function isBadVersion(version) that returns true if the version is bad, false otherwise.
โก Constraint: Minimize the number of API calls - each call is expensive!
Example: If you have versions [1,2,3,4,5] and version 4 was the first bad one, then versions 4 and 5 are bad, while 1,2,3 are good. Your function should return 4.
Input & Output
Visualization
Time & Space Complexity
Each iteration eliminates half of the remaining search space, so we need at most logโ(n) iterations
Only using constant extra space for the left, right, and mid pointers
Constraints
- 1 โค bad โค n โค 231 - 1
- At least one version is guaranteed to be bad
- Each call to isBadVersion() should be minimized for optimal performance