Domanda di colloquio di Apple

Binary search optimisation question from leetcode