Loading problem...
You are a software release manager overseeing a sequence of product releases. The development team has discovered that starting from a certain release, a critical defect was introduced that persists in all subsequent releases. This happens because each new release is built upon the previous one, so once a defect enters the codebase, it propagates to all future versions.
Given n releases labeled from 1 to n, your task is to identify the first defective release that introduced the bug. All releases from this point onward (inclusive) are considered defective.
You have access to an API function isDefective(release) that returns true if the given release number is defective, and false otherwise. Your goal is to implement a function that finds the first defective release while minimizing the number of API calls, as each call is computationally expensive and represents a time-consuming testing operation.
n = 5, bad = 44We need to find the first defective release among releases 1 through 5.
n = 1, bad = 11There is only one release, and it is defective. Therefore, the first defective release is 1.
n = 10, bad = 55Releases 1 through 4 are good, and releases 5 through 10 are defective. The first defective release is 5.
Constraints