Binary Search
Easyjavapythonccppjavascript
Given a sorted array of distinct integers and a target value, find the target using binary search.
Input Format
The first line contains two integers N and target. The second line contains N space-separated integers in strictly increasing order.
Output Format
Print the index of target, or -1 if it is not present.
Example 1
Input
5 7 1 3 5 7 9
Output
3
Explanation: 7 is located at index 3.
- 1 <= N <= 100000
- The array is sorted and all elements are distinct.
- -1000000000 <= A[i], target <= 1000000000