DIY: Missing Element in a Sorted Array

Solve the interview question "Missing Element in a Sorted Array" yourself in this lesson.

We'll cover the following

Problem statement

You are provided with a sorted array of integers, and you have to find the kthkth missing number in that array.

NOTE: The missing number can also exist beyond the provided sorted array.

Input

The input will be an array of integers and an integer value k. The following is an example input:

[4,7,9,10], 1

Output

The output should be the kthkth missing number from the array. The following is just an example output:

5

In the above case, k=1. Therefore, the first missing value in the array is 5.

Coding exercise

You need to implement the function missingElement(arr, k) where arr is the sorted array and k is the required missing number that you want to find. The function returns a single integer value representing the kthkth missing number in the array.

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