1539. Kth Missing Positive Number
1539. Kth Missing Positive Number
Description
Given an array arr
of positive integers sorted in a strictly increasing order , and an integer k
.
Return the k^th
positive integer that is missing from this array.
Example 1:
1 | Input: arr = [2,3,4,7,11], k = 5 |
Example 2:
1 | Input: arr = [1,2,3,4], k = 2 |
Constraints:
1 <= arr.length <= 1000
1 <= arr[i] <= 1000
1 <= k <= 1000
arr[i] < arr[j]
for1 <= i < j <= arr.length
Follow up:
Could you solve this problem in less than O(n) complexity?
Hints/Notes
- 2025/01/23
- Leetcode solution
Solution
Language: C++
O(log(n)) solution:
1 | class Solution { |
O(n) solution:
1 | class Solution { |