Given an infinite sorted array (or an array with unknown
size), find if a given Example 1:
Example 2:
Binary Search to Find the position of an element in a sorted infinite arrayGiven that the array is sorted, we can apply binary search to find the element. The only problem is that the array is infinite so we don’t know the bounds of the array. We will first try to find the bounds of the array within which the An efficient way to find the lower and upper bounds is to start at the beginning of the array with the lower bound at the 1st element (
Let’s look at the implementation: |