395. Missing Element in Sorted Array

Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

Example 1:

Input: nums = [4,7,9,10], k = 1

Output: 5

Explanation: The first missing number is 5.

Example 2:

Input: nums = [4,7,9,10], k = 3

Output: 8

Explanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.

Now Your Turn!

Pick the correct output for the given input

Input : nums = [1,2,3,4,10] , k = 11

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

1 <= nums.length <= 5 * 104

1 <= nums[i] <= 107

nums is sorted in ascending order, and all the elements are unique.

1 <= k <= 108

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int missingElement(vector<int>& nums, int k) {
// Your code goes here
}
};
Test Case

Input:

K
Nums