public static int search(ArrayReader reader, int key) {

```
int start = 0, end = key;
while (start <= end) {
int mid = start + (end - start) / 2;
if(reader.get(mid) == Integer.MAX_VALUE){
mid = start + (mid -start)/2;
}
if (key < reader.get(mid)) {
end = mid - 1;
} else if (key > reader.get(mid)) {
start = mid + 1;
} else { // found the key
return mid;
}
}
return -1;
```

}