First Bad Version
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.

leetcode island perimeter leetcode india leetcode intersection of two linked lists leetcode implement trie leetcode interview experience leetcode java leetcode javascript leetcode jump game leetcode java solutions leetcode jump game ii leetcode javascript solutions leetcode java questions leetcode jobs leetcode knapsack leetcode knapsack problem leetcode kth smallest element leetcode kmp leetcode k closest points leetcode kth smallest element in a bst leetcode kadane leetcode keys and rooms
Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.
You are given an API bool isBadVersion(version) which will return whether
version
is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
Example:
Given n = 5, and version = 4 is the first bad version.
call isBadVersion(3) -> false
call isBadVersion(5) -> true
call isBadVersion(4) -> true
Then 4 is the first bad version.
leetcode contest leetcode course schedule leetcode coin change leetcode company wise questions leetcode counting bits leetcode container with most water leetcode compensation leetcode challenge leetcode decode ways leetcode dark theme leetcode dfs leetcode data structures leetcode decode ways ii leetcode discuss leetcode daily temperatures leetcode edit distance leetcode explore leetcode easy problems leetcode errichto leetcode editor leetcode extension leetcode egg drop leetcode editorial leetcode flood fill leetcode find the town judge leetcode free leetcode founder leetcode for beginners
public class Solution extends VersionControl
{ public int firstBadVersion(int n) {
return find(1, n);
}
int find(int s, int e) {if (s == e) {return s;}
int m=s+(e-s)/2;
boolean notgood = isBadVersion(m);
if (notgood){
return find(s, m);
} else {
return find(m + 1, e);
}
} }