You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
You are given an API isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
Input: n = 5, bad = 4 Output: 4 Explanation: isBadVersion(3) -> False, isBadVersion(5) -> True, isBadVersion(4) -> True. Version 4 is the first bad version.
Input: n = 1, bad = 1 Output: 1 Explanation: Version 1 is the only version and it is bad, so it is the first bad version.
n = 5 bad = 4