sold holds the numbers of tickets already sold, in strictly increasing order.
Going through the numbers in ascending order, return the number of the k-th ticket that has not been sold.
A straightforward scan is O(n + k); try to find the answer in less than linear time.sold=[1, 3, 4, 8], k=3 → 6
The free numbers are 2, 5, 6, 7, 9, … The third of them is 6.
sold=[1, 2, 3], k=2 → 5
The first three numbers are taken in a row, so the free ones start at 4: 4, 5, … The second is 5.
sold=[6, 9], k=4 → 4
sold[i] < sold[i + 1]sold=[1, 3, 4, 8], k=3
6
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.