MetaOA #18
Kth Missing Positive Number (for E4 :)
Estimated EasyJudge-ready
Topics (AI-labelled)Binary Search
Given a strictly increasing array a of positive integers and a positive integer k, output the k-th positive integer that does not appear in the array.
Input
This site's standard input scale: the first line contains n k (1..100000, 1..10⁹), and the second line contains n strictly increasing positive integers (1..10⁹).
Output
Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.
Example 1
Input:
5 5
2 3 4 7 11
Output:
9
Example 2
Input:
4 2
1 2 3 4
Output:
6
Example 3
Input:
1 1
3
Output:
1
Example notes
Example 1: the missing numbers are 1, 5, 6, 8, 9 in order, so the 5th missing positive integer is 9.
Editorial
Loading solution…