Find the -th positive integer that does not appear in a strictly increasing sorted array.
You are given a strictly increasing array of positive integers. Some positive integers are missing from the array.
Return the -th positive integer that does not appear in the array when counting missing positive numbers in increasing order starting from $1$.
The array is already sorted and contains no duplicates, so you should use that structure to find the answer efficiently.
Input Format
- An integer array
arrof strictly increasing positive integers. - An integer
krepresenting which missing positive number to return.
Output Format
Return the -th missing positive integer.
Constraints
1 <= arr.length1 <= arr[i]arris strictly increasing1 <= k- The answer fits in a 32-bit signed integer
Example 1
Input
arr = [2,3,4,7,11], k = 5
Output
9
Explanation
The missing positive numbers are 1, 5, 6, 8, 9, 10, ... The 5th missing number is 9.
Example 2
Input
arr = [1,2,3,4], k = 2
Output
6
Explanation
The missing positive numbers are 5, 6, 7, ... The 2nd missing number is 6.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.