Position of an Element in an Infinite Sorted Array
Medium

Problem Statement

Given a sorted array of unknown size (infinite) and a target element, find the position of the target. You cannot use `length` property of the array.

Examples

1Example 1
Input:
{ "arr": [ 3, 5, 7, 9, 10, 90, 100, 130, 140, 160, 170 ], "target": 10 }
Output:
4
2Example 2
Input:
{ "arr": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], "target": 1 }
Output:
0
3Example 3
Input:
{ "arr": [ 2, 4, 6, 8, 10, 12, 14 ], "target": 15 }
Output:
-1
Loading...

Sign in to Run Code and Submit