Kth Missing Positive Number
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.

30:00

Kth Missing Positive Number
easy
Topics
Companies

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.

Example 1:
Input: {"arr":[2,3,4,7,11],"k":5}
Output: 9
Constraints:
  • 1arr.length10001 \leq \text{arr.length} \leq 1000

  • 1arr[i]10001 \leq \text{arr}[i] \leq 1000

  • All elements of arr are unique.

  • arr is sorted in strictly increasing order.

  • 1k10001 \leq k \leq 1000

Input
arr ={"arr":[2,3,4,7,11],"k":5}

Find 5th missing positive in sorted array

Left
Mid
Right
k = 5
Strictly Increasing Array
L

2

idx=0miss=1

3

idx=1miss=1

4

idx=2miss=1

7

idx=3miss=3
R

11

idx=4miss=6

Binary search range: [0, 4]

Expected: 1, 2, 3, 4, 5, ... | Given: [2, 3, 4, 7, 11] | Finding 5th missing
Variables
No variables to display
DepthFunction Call
Stack empty
0/7