less than 1 minute read

Given a list of sorted unique integers nums and an integer k, return the kth (0-indexed) missing number from the first element of the list.

Constraints

  • n ≤ 100,000 where n is the length of nums.

https://binarysearch.com/problems/Kth-Missing-Number

Examples

Example 1

Input

  • nums = [5, 6, 8, 9]
  • k = 3

Output

  • answer = 12

Explanation

The first four missing numbers are [7, 10, 11, 12]

Example 2

Input

  • nums = [5, 6, 8, 9]
  • k = 0

Output

  • answer = 7

Explanation

7 is the first missing number.

Solution

Categories:

Updated:

Leave a comment