Practice/Meta/Leetcode 1060. Missing Element in Sorted Array
CodingMust
You are given a strictly increasing integer array nums and a positive integer k. The array contains gaps - there are integers missing between consecutive elements and potentially before the first element.
Your task is to find the k-th positive integer that is missing from the array. The missing numbers start counting from 1 and include all positive integers not present in nums.
numsnums is guaranteed to be sorted in strictly increasing ordernums are positive integersExample 1:
Input: nums = [2, 4, 6, 8], k = 3 Output: 5 Explanation: The missing positive integers are [1, 3, 5, 7, 9, 10, 11, ...]. The 3rd missing number is 5.
Example 2:
Input: nums = [5], k = 2 Output: 2 Explanation: Missing numbers before 5 are [1, 2, 3, 4]. The 2nd one is 2.
Example 3:
Input: nums = [1, 2, 3, 4], k = 2 Output: 6 Explanation: The array is consecutive from 1 to 4, so the first missing number is 5 and the second is 6.