educative.io

Educative

Any comment on whether my approach below is efficient?

For the Question:
Given an infinite sorted array (or an array with unknown size), find if a given number ‘key’ is present in the array. Write a function to return the index of the ‘key’ if it is present in the array, otherwise return -1.

My approach was the following -
start = Integer.MAX_VALUE
for (reader.get(start) == Integer.MAX_Value) {
start = start/2
}
My thinking was that we can reach close to the mid of the array using this approachafter which t this point I can make a decision on which half the key would lie (if it exists)

@be_awesome_dude Have you written the entire code?
Problem with this is. Lets say it reaches some place where reader.get(start) != Integer.MAX_VALUE. Left part will have defined bounds from 0 to start (naming is problematic) , but right part still has same issue of end not defined.