Iterative binary search solution