Back to course home
0% completed
Solution: Search in a Sorted Infinite Array
Problem Statement
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.
Since it is not possible to define an array with infinite (unknown) size, you will be provided with an interface ArrayReader
to read elements of the array. ArrayReader.get(index)
will return the number at index; if the array’s size is smaller than the index, it will return Integer.MAX_VALUE
.
Example 1:
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible