FastPrepMissing Element in Sorted Array

Missing Element in Sorted Array

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

nums is strictly increasing. Starting after nums[0], consider positive integer values absent from the array in ascending order. Return the k-th missing value.

Function

missingElement(nums: int[], k: int) → int

Examples

Example 1

nums = [4,7,9,10]k = 3return = 8

The missing values are 5, 6, and 8.

Constraints

  • 1 <= nums.length <= 5 * 10^4.
  • 1 <= k <= 10^9.
  • The answer fits in signed 32-bit range.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int missingElement(int[] nums, int k) {
  // Write your code here.
}
nums[4,7,9,10]
k3
expected8
Checking account…