986 B
10.4. Sorted search, no size
You have an array-like data structure Listy which lacks a size method. It has an .elementAt(i) method returning the element at index i in O(1) time. If i is negative or bigger than the size, it returns -1. Given a Listy containing sorted, positive integers, find the index at which an element x occurs.
Initial approach would to check one by one starting from the beginning. O(n). Another is to try random checkups in the beginning, arr.elementAt(i) for i=10000, 1000, 100, 10. If x were to be bigger, start with a bigger i. It should give -1 until it's not 1 anymore. For example arr.elementAt(100)=X. If elem < X, do binary search between len(0, 100). If elem >= X, check arr.elementAt(200) and repeat, arr.elementAt(300) and repeat and so on.
Hints suggest an exponential backoff, starting with 2,4,8,16,etc until it hits -1. Then do binary search. Runtime will be O(log(n) + log(n)). First part for finding the length, second for binary search.