Kth Missing Positive Number

Easy

Description

Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the kth positive integer that is missing from this array.

Examples

Input:arr = [2,3,4,7,11], k = 5
Output:9
Explanation:

Missing: 1,5,6,8,9,10... 5th is 9.

Input:arr = [1,3,5,7,9], k = 3
Output:6
Explanation:

The array starts with 1, so the missing values are: 2, 4, 6, 8, 10, 11... The 3rd missing positive integer is 6.

Input:arr = [10,20,30], k = 7
Output:7
Explanation:

Missing positive integers are: 1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,21... The 7th missing positive integer is 7.

Constraints

  • 1 ≤ arr.length ≤ 1000
  • 1 ≤ arr[i] ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!