# Search In Big Sorted Array

```java
public class Solution {
    /*
     * @param reader: An instance of ArrayReader.
     * @param target: An integer
     * @return: An integer which is the first index of target.
     */
    public int searchBigSortedArray(ArrayReader reader, int target) {
        // write your code here

        //find right boundary
        //采用倍增法，一定能在第2k的地方找到比target 大的右边界
        int index = 1;

        while(reader.get(index-1) < target){
            index = index*2;
        }

        int start = 0, end = index;

        while(start + 1 < end){
            int mid = start + (end - start )/2;

            if(reader.get(mid) == target){
                end = mid;
            }
            else if(reader.get(mid) > target){
                end = mid;
            }else{
                start = mid;
            }
        }

        if(reader.get(start) == target){
            return start;
        }
        if(reader.get(end) == target){
            return end;
        }

        return -1;

    }
}
```
