DIY: Kth Missing Positive Number

Solve the interview question "Kth Missing Positive Number" in this lesson.

Problem statement

You are given an array, A, 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 <= A[i] <= 1000
  • 1 <= k <= 1000
  • A[i] <= A[j] for 1 <= i < j <= A.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:
A = [1,2,3,4]
k = 2

# Sample Input 2:
A = [2,3,5,9,10]
k = 4

# Sample Input 3:
A = [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.