Binary SearchArray
Given a sorted array of distinct integers and a target value, find the index of the target, or report that it is not present. Your solution should run in O(log n).
Input
Line 1: n and the target. Line 2: n integers in ascending order.
Output
Print the 0-based index of the target, or -1 if it is not in the array.
Constraints
1 <= n <= 10^5 -10^9 <= each value, target <= 10^9
Example 1
Input
6 9 -1 0 3 5 9 12
Output
4
9 is at index 4.
Example 2
Input
6 2 -1 0 3 5 9 12
Output
-1
2 is not present.