DIY: Missing Element in a Sorted Array

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

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.


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

[4,7,9,10], 1


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


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

Coding exercise

You need to implement the function missing_element(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 80+ hands-on prep courses.