Find Low/High Index of a Key in a Sorted Array

Given a sorted array of integers, return the low and high index of the given element.

Statement

We’re given a sorted array of integers, nums, and an integer value, target. Return the low and high index of the given target element. If the indexes are not found, return -1.

Note: The array can contain multiple duplicates with length in millions.

Example

In the array below, indices are shown in grey and values are shown in green. Note that the actual input can be very large in size.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.