Sorry but the solution is wrong

If the first bad revision is earlier than the mid your code will return the mid.

Example: GGBBBBB - If we'll start indexing from 1 and the function will be called with goodrevision=1 and badrevision=7 your code will return (7+1)/2 = 4. (Right answer is 3...).

Binary search is the right approach and an iterative impl' can be:

public static int findBadRevision(int goodRevision, int badRevision) {

while (true) {

int mid = (goodRevision + badRevision) / 2;

if (hasBug(mid)) {

if (mid == 0 || !hasBug(mid-1)) {

return mid;

}

badRevision = mid;

} else {

goodRevision = mid;

}

}

}

start with binary search approach and take the mid as

boolean foundBad = false;

while(!foundBad)

{

int revision = (goodrevision+badrevision)/2;

foundBad = hasBug(revision);

goodrevision = revision;

}

return revision;