I have two solutions for this problem. Both are essentially modified binary search algorithms. Why is my second implementation slower than the first one. I was expecting the second to converge in lesser number of iterations and hence faster!

Implementation 1: 18-19ms

```
public int firstBadVersion(int n) {
int lo = 1;
int hi = n;
while(lo < hi){
int mid = lo + (hi - lo)/2;
if(!isBadVersion(mid)) lo = mid + 1;
else hi = mid;
}
return hi;
}
```

Implementation 2: 44-45ms

```
public int firstBadVersion(int n) {
int hi = n;
int lo = 1;
while(lo < hi){
int mid = lo + (hi - lo)/2;
boolean a = isBadVersion(mid - 1);
boolean b = isBadVersion(mid);
boolean c = isBadVersion(mid + 1);
if(!a && b) return mid;
if(!b && c) return mid + 1;
if(!a && !b && !c) lo = mid + 1;
if(a && b && c) hi = mid - 1;
}
return hi;
}
```