The unknown length part is what got me initially.
Use exponential search to find a range where the target might exist, then apply binary search within that range. For duplicates, modify the binary search to find the first occurrence by continuing to search left when the target is found.
Pro tip: Exponential search is optimal for unbounded arrays, but be prepared to discuss its time complexity (O(log n)) and why it's better than linear scan or binary search with a fixed upper bound. Also, mention edge cases like empty array or target not present.
Confirm that the array is sorted in increasing order, may contain duplicates, and that get(i) returns infinity for out-of-bounds indices. Discuss handling of empty array and target not found.
Start with index 1 and double it until get(index) >= target or infinity is returned. This gives a range [index/2, index] where the target may exist.
Apply binary search on the identified range to find the target. If the target is not found, return -1.
When the target is found, continue searching leftwards to find the first occurrence. This can be done by adjusting the binary search to not stop at the first match.
Explain that exponential search takes O(log n) time and O(1) space. Discuss why this is optimal for unbounded arrays and compare with alternatives like linear scan.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.