FastPrepSearch an Unbounded Sorted Array
Problems/Search an Unbounded Sorted Array

Search an Unbounded Sorted Array

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem finds the position of a target value in an increasing list whose end is unknown, with reads past the end returning a very large number. An Adobe MTS 2 report lists, as its first-round coding question, a search on an array with no known end and an expected logarithmic time; it gives no input format, examples or edge rules.

Our choices: distinct values in increasing order (the report implies order only through the time bound), reads past the end return 2147483647, return the position or -1, at most 5000 values from -10^9 to 10^9 passed as an ordinary array, and new examples.

The judged task matches the report at about 70%.

You are given a list of distinct integers in increasing order, but you are not told where it ends. Reading any position past the last value gives 2147483647, which is larger than every real value.

Return the position (counting from 0) of target in the list, or -1 if it is not there. Aim for O(log p) reads, where p is the target's position (or where it would be).

In this exercise the list is passed as an ordinary array reader. Read it only through a small helper get(i) that returns reader[i], or 2147483647 when i is past the end, and do not use the array's length as a search bound.

Function

searchUnbounded(reader: int[], target: int) → int

Examples

Example 1

reader = [-8,-3,1,4,10,15,22]target = 10return = 4

The value 10 is at position 4 (counting from 0): -8, -3, 1, 4 come before it.

Example 2

reader = [2,6,9,13]target = 7return = -1

7 would sit between 6 and 9, but it is not in the list, so the answer is -1.

Example 3

reader = [5]target = 5return = 0

The only value is the target, at position 0. Every read past it returns 2147483647.

Constraints

  • 1 <= reader.length <= 5000
  • -10^9 <= reader[i] <= 10^9, and the values are distinct and in increasing order
  • -10^9 <= target <= 10^9

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int searchUnbounded(int[] reader, int target) {
    // Write your code here.
}
Checking account…