ORIGINAL CODING QUESTION
The k-th skipped ticket number
Ticket numbers handed out at a career fair are positive and strictly increasing, but some numbers were skipped by the printer. Return the k-th smallest positive integer that does NOT appear in the list. Missing numbers can lie beyond the last ticket.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n strictly increasing positive ticket numbers, then k. Print the k-th missing number.
Constraints
1 ≤ n ≤ 200; 1 ≤ ticket ≤ 1000; 1 ≤ k ≤ 1000.
Example 1
Input
4 1 4 5 9 3
Output
6
The missing numbers begin 2, 3, 6, so the third is 6.
Example 2
Input
3 1 2 3 2
Output
5
Nothing is skipped inside the list; the missing numbers are 4, 5, ...
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Before index i, exactly a[i] - (i + 1) positive numbers are missing.
Hint 2
That count never decreases, so binary search for the first index where it reaches k.
Hint 3
If that first index is lo (possibly n), the answer is lo + k.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →