Apple interview question

Binary search optimisation question from leetcode