DIY: Kth Missing Positive Number
Solve the interview question "Kth Missing Positive Number" in this lesson.
We'll cover the following
Problem statement
You are given an array, arr
, of positive integers only and an integer, k
. The array is sorted in a strictly increasing order. Your task is to find the kth
positive integer that is missing from this array.
Constraints
1 <= arr[i] <= 1000
1 <= k <= 1000
arr[i] <= arr[j] for 1 <= i < j <= arr.length
Input
The input will be an array of positive integers, sorted in ascending order, and an integer, k
. The following are examples of the input to the function:
# Sample Input 1:
arr = [1,2,3,4]
k = 2
# Sample Input 2:
arr = [2,3,5,9,10]
k = 4
# Sample Input 3:
arr = [1,97,101,654,798,989,1000]
k = 100
Output
The output will be an integer. Here are some examples of the output:
# Sample Output 1:
6
# Sample Output 2:
7
# Sample Output 3:
103
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.