← 返回 amazon 的题目列表Find Index of K in Array with Unknown Length
类型:online_judge
Given an integer array that can only be accessed through a get(i) method, where i is a zero-based increasing integer index, assume the length of the array is unknown. Implement a method to find the index of an element k in the array, assuming the array is sorted in increasing order. Return -1 if the element does not exist.
Input:
get(i): Returns the i-th element of the array.
k: Target integer.
Output:
Index of k, or -1 if not found.
Requirements:
Ensure get(i) method calls are minimized as they are expensive.