New update is available. Click here to update.

Topics

You are given an integer array ** 'A'** of size

Your task is to write a function to search for * 'target'* in the array

Note:

```
You must write an algorithm whose time complexity is O(LogN)
```

```
Input: ‘N’ = 7 ‘target’ = 3
‘A’ = [1, 3, 7, 9, 11, 12, 45]
Output: 1
Explanation: A = [1, 3, 7, 9, 11, 12, 45],
The index of element '3' is 1.
Hence, the answer is '1'.
```

Detailed explanation

```
1 <= N <= 10^5
1 <= A[i] <= 10^9
1 <= target <= 10^9
Time Limit: 1 sec
```

```
7
1 3 7 9 11 12 45
3
```

```
1
```

```
nums = [1, 3, 7, 9, 11, 12, 45],
The index of element '3' is 1.
Hence, the answer is '1'.
```

```
7
1 2 3 4 5 6 7
9
```

```
-1
```

```
nums = [1, 2, 3, 4, 5, 6, 7],
Element '9' doesn't exist.
Hence, the answer is '-1'.
```