A new fitness studio numbers its lockers with every positive integer 1, 2, 3, …, and hands them out to members one at a time. You are given the sorted, strictly increasing list of locker numbers already assigned to current members. Whenever the front desk assigns a new locker, it always chooses the smallest number that has never been assigned; determine which locker number the k-th such still-unassigned locker (counting from the smallest upward) would be.
n and k.n integers, the already-assigned locker numbers, strictly increasing.Print a single integer: the k-th smallest positive integer that does not appear in the assigned list.
Example 1
Input
4 3 3 5 8 10
Expected
4
Explanation
Assigned lockers are 3, 5, 8, 10. Counting positive integers in order and skipping assigned ones: 1 is the 1st vacant number, 2 is the 2nd, and 4 is the 3rd (since 3 is assigned). So the 3rd vacant locker number is 4.
Example 2
Input
4 2 1 2 3 4
Expected
6
Explanation
Assigned lockers are 1, 2, 3, 4 with no gaps among them, so vacant numbers start right after: 5 is the 1st vacant number and 6 is the 2nd, giving an answer of 6.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →