more elegant solution

Key fact: middle element divides array in two parts, and one of them
will always be strictly sorted. That's where we take advantage of and
check target value against it.