LeetCode 704 Binary Search - Problem Statement

The problem

You're given a sorted array and a target value. Your task is to find the index of the target, or return -1 if it doesn't exist.

For [-1,0,3,5,9,12] with target=9, you'd return 4 since the element at index 44 is 99.

You could scan left to right in O(n)O(n), but there's a faster approach. Since the array is sorted, think: how can you eliminate half the remaining elements with each comparison?

Constraints: 1n1041 \le n \le 10^4, array is sorted with unique values.