Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > The K-th Missing Number

The K-th Missing Number

Difficulty: 1500 3000 ms 128 MB

binary-search

A strictly increasing array of positive integers is given. Print the K-th positive integer that does NOT appear in it.

Input: the first line has N and K; the second line has the N sorted values.

Output: the K-th missing positive integer.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ K ≤ 105
  • 1 ≤ ai ≤ 2×105, strictly increasing

Sample Tests

Input 1
4 2
2 3 4 7
Output 1
5
Input 2
2 4
1 2
Output 2
6

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen