# 0702. Search in a Sorted Array of Unknown Size

<https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size>

## Description

This is an ***interactive problem***.

You have a sorted array of **unique** elements and an **unknown size**. You do not have an access to the array but you can use the `ArrayReader` interface to access it. You can call `ArrayReader.get(i)` that:

* returns the value at the `ith` index (**0-indexed**) of the secret array (i.e., `secret[i]`), or
* returns `231 - 1` if the `i` is out of the boundary of the array.

You are also given an integer `target`.

Return the index `k` of the hidden array where `secret[k] == target` or return `-1` otherwise.

You must write an algorithm with `O(log n)` runtime complexity.

**Example 1:**

```
**Input:** secret = [-1,0,3,5,9,12], target = 9
**Output:** 4
**Explanation:** 9 exists in secret and its index is 4.
```

**Example 2:**

```
**Input:** secret = [-1,0,3,5,9,12], target = 2
**Output:** -1
**Explanation:** 2 does not exist in secret so return -1.
```

**Constraints:**

* `1 <= secret.length <= 104`
* `-104 <= secret[i], target <= 104`
* `secret` is sorted in a strictly increasing order.

## ac

```java
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/0702-search-in-a-sorted-array-of-unknown-size.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
