443. Find Kth Missing Positive Number

EasyBinary SearchArrayBinary Search

Given a sorted positive integer array arr and an integer k, return the k-th missing positive integer not present in arr.

Input: A sorted positive integer array arr and integer k.

Output: The k-th missing positive integer.

Examples

Example 1
Input: [2,3,4,7,11], 5
Output: 9
Explanation: Missing positives: 1,5,6,8,9,... 5th missing is 9.
Example 2
Input: [1,2,3,4], 2
Output: 6
Explanation: Missing: 5,6,7,... 2nd is 6.
Example 3
Input: [5,6,7,8,9], 1
Output: 1
Explanation: 1st missing is 1.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →