This is a classic binary search problem, which I always struggle to get after not looking at it for some time.
There are many ways to accomplish, I will present 5 ways:
- The standard way without knowledge of abstract binary search theory (both iterative and recursive)
- Evaluation the following predicate: p(x): A[x] >= target
- Evaluation of the following predicate: p(x): A[x] > target